3 ms·
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);
by cel1ne 10y ago
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 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.