Hacker News new | ask | show | jobs
by tkahn6 5380 days ago
> If Foo can "foo" and Bar can "bar", Foo can't "bar". But if you have "null", then suddenly it can "foo" and "bar" even though it's not a subtype of anything that can do that, and it doesn't implement those methods itself.

Can't believe I'm defending Java's type system but I'm pretty sure you can only call bar on a null Foo (Foo f = null) if you cast it to a Bar first. Otherwise it'll fail to type check. What Java does allow you to do is call foo on a null Foo and in that case you get a null pointer exception at runtime.