3 ms·
I think the point isn't the Maybe stuff - Int? - but the non-nullable reference types. In conventional Java, every reference type is always nullable, so there's
by ufmace 11y ago
I think the point isn't the Maybe stuff - Int? - but the non-nullable reference types. In conventional Java, every reference type is always nullable, so there's no way to strictly differentiate between things that couldn't possibly be null, and so don't need checking, and things that have a valid reason for being null, and should be checked and handled properly.
Kotlin allows non-nullable reference types, so you can declare a method as taking a non-nullable reference to an object. Now within that method, you know that reference is never null, and don't need to check it. When you call it, you have to either check for null beforehand, or pass something that is already guaranteed not to be null.
It's kind of like it builds a wall between things that could be null, and things that can't be, instead of having theoretical potential nulls all over your code. When you think about it, it seems like a pretty natural thing for a strongly-typed language to do.
- kragen 11y agoI agree that non-nullable reference types are a big advantage. (People who haven't programmed in Java might underestimate how big a problem null pointers are in Java.)