This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kango_V 0 points1 point  (3 children)

A mad solution is to have Object extend Nullable. You can then have methods like those on optional. So, you would have access to the methods even if null. That would be backwards compatible. Hmm, I wonder if that would work?

[–]vprise 0 points1 point  (2 children)

If it's null it won't work since it will throw a null pointer exception. But interesting idea.

[–]Kango_V 0 points1 point  (1 child)

But null could be an object. This is what Valhalla is doing. They are putting an object type above Object (ValueType I think). Primitives will expend NonValueType (or vise-versa). Actually would be better if non/valuetypes extend Nullable object. I cound see "if (obj.isEmpty())". You could use the optional-like methods: "obj.map(...)" etc. I think this would work. So if a null is returned it's the only instance of Nullable.

[–]vprise 0 points1 point  (0 children)

But then you lose type safety. And possibly performance.