


I never have used rust before so I can’t compare the nullable types with rusts optionals. Yes, but that also has nothing to do with Optionals vs the nullable types.

Optionals don’t stop java passing null where it is not supposed to and Optionals don’t stop you from doing stupid stuff using reflection.Ĭould Kotlin prevent the problem with NPEs in constructor calls. Does that mean that kotlins null system prevents all “normal” variables from being not null? No, but that is not possible on the jvm as long as you leave the kotlin eco system. It’s a way to tell the type system that a value can be null, which enables the compiler to force you to check the existence of a value before accessing it. IMO kotlins null system does exactly the same thing as Optionals do. Optional has different pros and cons to kotlins null system.
