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.htmlIt really is an awesome language. Especially the delegated properties are wonderful. I use them to fill javascript-state for redux/react-native.
> 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.