3 ms·
Java's optionals are incredibly half-baked IMO, and I say this as someone who is generally quite pro-Java. They make the code slower, harder to read and don't
by marginalia_nu 4y ago
Java's optionals are incredibly half-baked IMO, and I say this as someone who is generally quite pro-Java.
They make the code slower, harder to read and don't really solve any problem.
- valenterry 4y agoYeah, in particular since you cannot have Some(null) which is just very bad design because it makes interaction with code that uses null impossible (or unreliable). And syntactically, it's not a pleasure to use, but that's more a fault of Java being so verbose and limited in terms of the typesystem, not a fault of the Optional type.
- marginalia_nu 4y agoI don't think amending the type system (or using the existing type system) would make sense for Java. I think either a null-delegating operator (like C#'s foo.?bar ); or a variable modifier (a bit like 'final') that doesn't permit nulls would make far more sense in the context of the language at large. In fact, the approach is commonly enforced through annotations and static analysis. Built-in support for the construct would be very beneficial.
- valenterry 4y agoYeah, I agree.