2 ms·
The issue isn't so much whether it is null, but whether it can be null. Because if it can be null, you have to check whether it is null before you can actually
by mcv 4y ago
The issue isn't so much whether it is null, but whether it can be null. Because if it can be null, you have to check whether it is null before you can actually do anything with it. That adds a lot of null-checking boilerplate to your code.
If instead the compiler can guarantee that a value will never be null, then you don't have to check, leading to cleaner code. Scala does this with the Option type, Typescript by forcing you to declare a type as `string|null` if it can be null. These sort of things make your code safer and cleaner.
- kaba0 4y agoJust a note, Scala 3 has an optional compiler flag to remove null from the type system meaning String can’t contain an NPE.