Hacker News new | ask | show | jobs
by jrockway 5380 days ago
QA is the wrong solution to this particular problem. The problem is that in Java you can call methods on uninitialized objects. 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. Does that sound fucked up? Well, that's because it is.

QA is nice, but it's a finite resource that you should save for things that actually matter, not stupid things that a computer can fix for you in 30 seconds.

1 comments

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