3 ms·
There's no reason that something can't both an object and the bottom of the type hierarchy. It's, technically, an instance of multiple inheritance. Java doesn'
by Kamq 2y ago
There's no reason that something can't both an object and the bottom of the type hierarchy.
It's, technically, an instance of multiple inheritance. Java doesn't generally allow this, but there's tons of special cases in the compiler for things that you can't do yourself. For example, defining operators is done in the compiler, but you can't define operators for your own classes.
- DaiPlusPlus 2y agoIt would be a bottom-type of reference-types. This wouldn’t work for value-types like int, at least not without boxing, which would be very painful.
- Kamq 2y agoFair, but those are kind of off in their own in the java hierarchy as is.
- chopin 2y agoBut an int can't be null. If a method takes or returns an int it's guaranteed to be not null.
- DaiPlusPlus 2y ago…yes; that’s my point.
- codebje 2y agoIt's the other way around: null needs to be a subtype of MyType, not a supertype: anywhere I can pass a MyType I should be able to pass a null. You could get most of the way to the blog post's outcomes by simply adding a few methods to Object (is(Not)Null, primarily) and having null be a magic (because it's all classes and none) instance that will NPE on all but the few defined Object methods, I think, but none of that answers the burning question of _why_ that I feel the article doesn't really address.
- Kamq 2y agoCorrect. In type theory, a type that is a subtype of all other types is called a bottom type: https://en.wikipedia.org/wiki/Bottom_type https://en.wikipedia.org/wiki/Bottom_type