99% Don't Know About THIS In Kotlin 😱

Поділитися
Вставка
  • Опубліковано 20 гру 2022

КОМЕНТАРІ • 34

  • @unclechaelsneckvein
    @unclechaelsneckvein Рік тому +15

    I always wanted to store a break statement's return value. Now I can finally do it.

  • @naskar23
    @naskar23 Рік тому +22

    Thanks Philip for another informative quick byte. Rocking as usual.
    Just a small doubt... when and how do we use this ? As in like an use case

    • @PhilippLackner
      @PhilippLackner  Рік тому +14

      It's more an informational piece so you get a deeper understanding of how Kotlin, its type system and the compiler works :) Not really something you can directly implement in your project

    • @vibovitold
      @vibovitold 11 місяців тому +5

      ​@@PhilippLacknerof course you can, let's say you've got multiple when expressions (exhaustive), and you throw exceptions for some of the branches, because these values aren't supported. but those exceptions are identical, or very similar to eachother. so you can just encapsulate it in a function like "throwUnsupported", to reduce repetition. and it will return Nothing just like in your example. that's a real-life use case from literally like a week ago in my project.

  • @josephofem5448
    @josephofem5448 Рік тому +3

    This tip couldn't have come at a better time. Thanks phil

  • @TheBlackManMythLegend
    @TheBlackManMythLegend Рік тому +3

    The goal for me is to write readable code

    • @livedreamsg
      @livedreamsg 10 місяців тому

      "break" or "return" aren't readable enough for you?

  • @dmitrimatantsev1898
    @dmitrimatantsev1898 Рік тому +1

    Boundless capabilities of Kotlin 💪

  • @jesprotech
    @jesprotech Рік тому +2

    Ok great, but in what way does this feature represents an advancement in relation to Java? This question comes purely out of curiosity.

  • @manshalkhatri9289
    @manshalkhatri9289 Рік тому +20

    Any useful example of this technique?

  • @alimrad7760
    @alimrad7760 9 місяців тому +1

    Like TODO() function

  • @alexnovikov1609
    @alexnovikov1609 Рік тому

    Thank you!🔥

  • @insanegamer5698
    @insanegamer5698 Рік тому

    I am a beginner and yr tips are amazing 🎉

  • @rajnarayan9558
    @rajnarayan9558 10 місяців тому

    Hey philip what's your vs code theme

  • @rhen4610
    @rhen4610 Рік тому

    Im curios, will u ever do iOS/Swift development content?

  • @s-w
    @s-w Рік тому +2

    Y tho

  • @negaaa5080
    @negaaa5080 Рік тому +7

    Ok. But why

    • @thijs-de-haan
      @thijs-de-haan Рік тому +2

      To be able to return nothing when any other type is expected.
      It doesn't make sense to store them in a variable, but it does make sense to return it from a function, the single-expression function.

    • @robchr
      @robchr Рік тому +1

      Generics

  • @krtirtho
    @krtirtho 9 місяців тому

    Make it infix and and it'll appear as keyword

  • @gregoryphiri5724
    @gregoryphiri5724 Рік тому +1

    TODO()

  • @gori_maheswari8994
    @gori_maheswari8994 Рік тому

    👌👌

  • @orangasli2943
    @orangasli2943 Рік тому

    How can we implement only one function from an interface if that interface has many functions that needs to be overriden?

    • @billanderson5727
      @billanderson5727 Рік тому +1

      We MUST implement all the methods of the interface. Interface is a CONTRACT between classes, it 'binds' them to implement all the methods if they come into a 'binding' with the interface.

    • @orangasli2943
      @orangasli2943 Рік тому

      @@billanderson5727 I watch a tutorial on how to create game in android studio..but a function used was deprecated..
      And now android says I need to implement a function from an interface..
      But I only want to use only one function..inside there there are many functions that needs to be implemented from Android development documentation

    • @orangasli2943
      @orangasli2943 Рік тому

      @@billanderson5727 besides I don't know what code should I write

    • @Fo0nT
      @Fo0nT Рік тому

      You just provide a default empty implementation by adding curly braces to the function. If you need to use the function from Java, annotate it with @JvmDefault as well.

    • @Fo0nT
      @Fo0nT Рік тому

      If you don't have access to the original interface, you can extend it

  • @MiguelCastanon
    @MiguelCastanon 11 місяців тому

    Is this similar to Null statment?

    • @ispite
      @ispite 10 місяців тому

      nope, nothing is final class in class hierarchy

  • @pratikdhage3491
    @pratikdhage3491 Рік тому

    🙃

  • @kam311
    @kam311 Рік тому +1

    I'm that 1% 🦾

  • @ashar9327
    @ashar9327 Рік тому

    I'm not in the 1% 🫤