Hacker News new | past | comments | ask | show | jobs | submit login

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.




It'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.


Correct. 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


It 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.


But an int can't be null. If a method takes or returns an int it's guaranteed to be not null.


…yes; that’s my point.


Fair, but those are kind of off in their own in the java hierarchy as is.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: