17
Comments
  • 1
    Why the return?
  • 1
  • 1
    Try python once 😆
  • 2
    The linter warning marked on the return statement says that this is nonsensical because it cannot be reached: the null!! expression throws before the return is reached.

    Expert question: do you know the inferred return type of this return statement? Even something that doesn't return a value has a return type in Kotlin!
  • 1
    @eeee i would assume either "Unit?" or "Nothing?" ?
    i've not use kotlin that much
  • 2
    @Trithon it's Nothing.

    That makes sense because Nothing is a subtype of all types, but cannot be instantiated. So a function that is declared to return a String, but throws, is valid because it then 'returns' Nothing and execution stops there, because the thrown Throwable must be handled by some catcher.

    Throwing is basically a forking point in a thread's execution.

    This is also valid Kotlin. Note that this is not a Nothing instance, because the type is Nothing or null, and the value is null. Nothing can't be instantiated (unless there's a bug in the Kotlin compiler).

    @highlight

    val whatAmI: Nothing? = null
  • 1
  • 1
    seriously fuck Kotlin, I had to refactor twice in a month due to Kotlin updates, I hate it so much, nothing makes sense in Kotlin... can't wait for the day we finally delete the last fucking .kt file from the project at work. (we are gradually rewriting everything in Java)
  • 0
    In Javascript this would evaluate to boolean false... 🤔
Add Comment