Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Kotlin has compile-time null-safety. The ? denotes a type than can be null.

    fun myFunction(x: Number?) {
       if (x == null) return;
       print(x + 1);
    }
if you don't check for null first the compiler warns.

You can also do:

    x?.let {notNullX -> print(notNullX + 1)}
or

    print((x ?: 4) + 1)
https://kotlinlang.org/docs/reference/null-safety.html

It really is an awesome language. Especially the delegated properties are wonderful. I use them to fill javascript-state for redux/react-native.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: