4 ms·
What makes option useless
by zaphirplane 4y ago
What makes option useless
- lmm 4y agoDeliberate weird behaviour around nulls. In particular you can't have Some(null), which means you can't really use it to solve the problems it's meant to solve - one of the key motivating examples for why you want optionals is that if Map.get(x) returns null, you don't know if that means there's no mapping for x in the map, or there's an entry with key x and value null. So the idea would be to add Map.safeGet or some such which returns Option<V>, and then if it returns None there's really no mapping, and if it returns Some(null) then there's a mapping with value null. But you can't do that in Java because in the standardisation process they decided they... didn't want to allow it.
- AzzieElbab 4y agoI thought it was wrapping successful Java calls that return nulls. Try.toOption caught me off guard with this behaviour
- lmm 4y agoDid you reply to the wrong comment? I'm talking about Java's Optional implementation.
- zaphirplane 4y agoIsn’t that a map of optionals Optional::Empty, optional with value or null ? Your 3 states
- lmm 4y agoThat's a lot more cumbersome to work with, and only possible at all if you're controlling the construction/population of the map rather than getting it back from a library or framework.