3 ms·
Kotlin can do something similar, in fact I think the code would work exactly like that if you ported it, but it can also do things like: > if (a instanceOf Som
by tomjen3 10y ago
Kotlin can do something similar, in fact I think the code would work exactly like that if you ported it, but it can also do things like:
> if (a instanceOf SomeClass && a.someGetterOnSomeClassNotAvailableOnTheStaticTypeOfa != null)
Which is pretty awesome because it means you don't have to pollute your code with unnecessary casts.
- cel1ne 10y agoKotlin 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 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.