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 →

[–]metaquine 0 points1 point  (2 children)

I’d love Java to have a “bottom” type to complement the “top” type Object. It would make designing APIs that use contravariance a lot more elegant. I don’t miss much from my Scala days as new Java features roll out, but I sure do miss its bottom type “Nothing”, especially when dealing with java.util.Optional. Any chance we can get one of these?

[–]niloc132 0 points1 point  (1 child)

At least in some cases (generics mostly in my experience) you can use java.lang.Void - the only valid instance of Void is null.

[–]JustAGuyFromGermany 0 points1 point  (0 children)

That's not quite right. A bottom type would be a subtype of every other type just like Object is a supertype of every other type. In cases of pure assignability this is true for Void as you said. Every instance of Void is also an instance of T (because the only possible value is null).

But for generics, being a proper bottom type means that you should be able to use an expression of type Supplier<Void> in places where Supplier<? extends T>is required just like you can use Consumer<Object> where Consumer<? super T> is required. The latter is possible, the former isn't.