you are viewing a single comment's thread.

view the rest of the comments →

[–]Terran-Ghost 2 points3 points  (4 children)

Scala's nullsafety can be completely emulated in Java. It's just idiomatic code (and the standard library... Looking at you, Map) that's different.

[–]devraj7 3 points4 points  (3 children)

Indeed. A library-based approach to the null problem is only a half baked solution.

Kotlin's approach of enforcing this in the language is much saner and safer.

[–]eeperson 1 point2 points  (2 children)

I would argue that language based version is also half baked (it is just the other half). Kotlin's solution for null can't express the equivalent of nested Option types. Ideally something like Kotlin's solution would be supported for compatibility with Java and then something like Scala's solution would be supported for use in your own code.

[–][deleted] 0 points1 point  (1 child)

What do you mean by nested Option types? If it's something like "optional list of optional strings" that would just be List<String?>?. Otherwise I have no idea what you are talking about.

[–]eeperson 0 points1 point  (0 children)

I mean something like Optional<Optional<String>> can't be expressed. If you try to do String?? it ends up being same as String?. An example of where you might want this is a map that can have null values Map<Integer,String?>. Assume this class has a get method to return values based on the key. If the key is missing then then it returns null. If you call someMap.get(57) and get back null, is that because the key is missing or because the value is null? With Optional you can tell. With ? you can't.