Every Kind of Class in Kotlin

Поділитися
Вставка
  • Опубліковано 25 лип 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
  • Наука та технологія

КОМЕНТАРІ • 33

  • @ArthurKhazbs
    @ArthurKhazbs 3 місяці тому +20

    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  3 місяці тому +4

      Yes, thank you for pointing that out, Arthur!

  • @foreverrafs
    @foreverrafs 3 місяці тому +21

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

    • @typealias
      @typealias  3 місяці тому

      Great, thank you so much!

  • @Doruko666
    @Doruko666 3 місяці тому +4

    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  3 місяці тому +1

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

  • @ivanvega9100
    @ivanvega9100 3 місяці тому +3

    I really like your teaching style, thank you!

    • @typealias
      @typealias  3 місяці тому

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

  • @UsmonWasTaken
    @UsmonWasTaken 3 місяці тому +3

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

  • @kqvanity
    @kqvanity 3 місяці тому +1

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

    • @typealias
      @typealias  3 місяці тому +1

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

  • @hhhapz
    @hhhapz 3 місяці тому +6

    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  3 місяці тому +3

      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 3 місяці тому +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  3 місяці тому +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 3 місяці тому

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

    • @Kinasawa
      @Kinasawa 25 днів тому

      I started combining this with Display name and the test output reads beautifully, specially with parametrized tests

  • @husammuala
    @husammuala 3 місяці тому +2

    Thank you so much Dave your tutorials are always helpful

    • @typealias
      @typealias  3 місяці тому +1

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

  • @superhumandose
    @superhumandose 3 місяці тому +1

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

    • @typealias
      @typealias  3 місяці тому

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

  • @ivastojkovic7904
    @ivastojkovic7904 3 місяці тому

    Great stuff!

  • @bernard-ng
    @bernard-ng 3 місяці тому

    This is what I was looking for 😊🎉

  • @calixtoandrade996
    @calixtoandrade996 2 місяці тому

    great video
    thanks

  • @CommanderSteps
    @CommanderSteps 3 місяці тому

    Well done!

  • @scottbiggs8894
    @scottbiggs8894 2 місяці тому

    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).

  • @mkjvd
    @mkjvd 19 днів тому

    Awsm

  • @baer126
    @baer126 2 місяці тому

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

    • @typealias
      @typealias  2 місяці тому

      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!

  • @Amejonah
    @Amejonah 3 місяці тому +1

    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.

  • @zeusalmighty6740
    @zeusalmighty6740 3 місяці тому

    Object?

    • @typealias
      @typealias  3 місяці тому +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 Місяць тому

    Freshers can’t understand ur vdos