Every Kind of Class in Kotlin

Sdílet
Vložit
  • čas přidán 20. 06. 2024
  • Kotlin offers many different kinds of classes, and in this video, we're gonna look at all of them - regular classes, nested classes, inner classes, data classes, inline value classes, enum classes, sealed classes, and annotation classes! By the end of this video, you'll understand these different kinds of classes and when to consider using each one.
    ✨ New to Kotlin? Start your journey here: typealias.com/start/
    ... or pick up the new Leanpub Edition for offline access and more! book.typealias.com/
    🚀 Get the inside scoop on everything I'm working on - join my brand new email newsletter!
    Sign up here: newsletter.typealias.com/
    00:00 Introduction
    00:27 Classes
    01:03 Nested Classes
    02:41 Inner Classes
    03:54 Data Classes
    05:19 Value Classes
    06:48 Enum Classes
    07:42 Sealed Classes
    08:39 Annotation Classes
    09:45 Wrap-Up
  • Věda a technologie

Komentáře • 33

  • @ArthurKhazbs
    @ArthurKhazbs Před 2 měsíci +12

    Another thing to remember is that in Kotlin, unlike in Java, regular classes are final by default, which means they cannot be subtyped. To make a class open for subtyping, it has to be marked with the "open" modifier.

    • @typealias
      @typealias  Před 2 měsíci +3

      Yes, thank you for pointing that out, Arthur!

  • @foreverrafs
    @foreverrafs Před 2 měsíci +15

    I like your presentation style, very succint and straight to the point

    • @typealias
      @typealias  Před 2 měsíci

      Great, thank you so much!

  • @Doruko666
    @Doruko666 Před 2 měsíci +3

    I don't know where did you come up, but you're the great teacher a lot of us never had. Keep on the good work Dave :)

    • @typealias
      @typealias  Před 2 měsíci +1

      I appreciate that - thanks so much! I'll keep at it!

  • @UsmonWasTaken
    @UsmonWasTaken Před 2 měsíci +2

    The people who haven't subscribed to Dave are probably gonna miss a lot of things 😅

  • @hhhapz
    @hhhapz Před 2 měsíci +4

    This is a great video, but this video also embodies my biggest gripe with Kotlin. It feels like every potential feature that could maybe be useful in any circumstance was indiscriminately added to the language. Useful, yes, but it gives every single project a different feel and makes it difficult to find consistency, sometimes even within the same project. This is especially felt when using different libraries together.

    • @typealias
      @typealias  Před 2 měsíci +2

      I can understand that perspective - that's actually how I felt about Groovy. I found it to be a very capable language, but there were so many features and options - even blending dynamic and static typing - that it didn't seem to have a sense of direction, and I suspect even detracted from adoption. I'm hoping Kotlin will avoid _that_ level of feature sprawl - it's a good concern to keep in mind, for sure!

  • @Alchemist10241
    @Alchemist10241 Před 2 měsíci +3

    using @Nested inside the test class tip was awesome, most of the time naming test cases is difficult for me but by grouping them using @Nested, naming would be much easier and straight forward. great video by the way

    • @typealias
      @typealias  Před 2 měsíci +1

      Thanks! Yeah, once I started using `@Nested` in those JUnit 5 tests, I really missed it on the occasions when I had to return to JUnit 4.

    • @kqvanity
      @kqvanity Před 2 měsíci

      @@typealias When do you usually revert back to JUnit4? For me, it's usually when interacting with Roboelectric or such

  • @kqvanity
    @kqvanity Před 2 měsíci +1

    I usually have a hard time when the examples are contrived, but yours are great : )

    • @typealias
      @typealias  Před 2 měsíci +1

      Thank you for saying that - I try my best to come up with examples that fit well!

  • @ivanvega9100
    @ivanvega9100 Před 2 měsíci +3

    I really like your teaching style, thank you!

    • @typealias
      @typealias  Před 2 měsíci

      Thank you so much! I'm glad you like it!

  • @calixtoandrade996
    @calixtoandrade996 Před měsícem

    great video
    thanks

  • @ivastojkovic7904
    @ivastojkovic7904 Před 2 měsíci

    Great stuff!

  • @husammuala
    @husammuala Před 2 měsíci +2

    Thank you so much Dave your tutorials are always helpful

    • @typealias
      @typealias  Před 2 měsíci +1

      Thank you so much! I'm glad you like them!

  • @CommanderSteps
    @CommanderSteps Před 2 měsíci

    Well done!

  • @superhumandose
    @superhumandose Před 2 měsíci +1

    Thank you soo much Dave, you are a gift to all beginners

    • @typealias
      @typealias  Před 2 měsíci

      Hey, you're welcome! It took a while to get around to it, but I appreciate you requesting this one!

  • @scottbiggs8894
    @scottbiggs8894 Před měsícem

    Just found your channel. Nice video: cleanly produced, smartly packaged, and thorough without being tedious. Thank you.
    Hmm, never used value classes before--talk about boilerplate code!!! That is sooooo awkward, just to catch a parameter error. But that's kotlin for you: tons of extra work in order to keep bad programmers from making mistakes. Give me plain ol C any day (or Lisp).

  • @bernard-ng
    @bernard-ng Před 2 měsíci

    This is what I was looking for 😊🎉

  • @baer126
    @baer126 Před měsícem

    I wanted to learn kotlin, do I need to learn Java?

    • @typealias
      @typealias  Před měsícem

      Hey Dani! You can certainly learn Kotlin without knowing Java. Sometimes, knowing Java can be a bonus, and could be helpful if you wanted to use a Java library in Kotlin, for example.
      You're welcome to start learning Kotlin here: typealias.com/start. In that online book, I don't expect the reader to have any prior Java experience. There are a few occasions where I mention things that might be helpful for someone who is coming from Java, but that's about it. Let me know how it goes as you start learning Kotlin!

  • @_zantetsuken_
    @_zantetsuken_ Před 2 měsíci +1

    For the algo! Thanks youtube to get me here.

    • @typealias
      @typealias  Před 2 měsíci

      Haha, much appreciated! 😁

  • @zeusalmighty6740
    @zeusalmighty6740 Před 2 měsíci

    Object?

    • @typealias
      @typealias  Před 2 měsíci +1

      Yeah, I decided not to include `object` since it's not quite in the same category... e.g., you can create nested objects and data objects. Might have made a good honorable mention, though!

  • @rohitkalkar8006
    @rohitkalkar8006 Před 6 dny

    Freshers can’t understand ur vdos

  • @Amejonah
    @Amejonah Před 2 měsíci

    8:20 I generally use sealed interfaces for that, because they don't store any state and are purely for grouping these sub-classes into a single type.
    Unfortunately, the youtrack issue KT-50630/Script-false-positive-NOELSEINWHEN-for-sealed-interface-hierarchy appeared and limits it in when clauses, which is kinda sad at the moment.
    I'd argue that sealed classes are to take when it needs to be scoped and have a common property, whereas interfaces should be used as a default.