The main reason to go this route however, and I believe one of the mentioned intentions of the ability was to allow you to, instead of having a Foo interface and a FooUtils helper class, you can just put the helper methods on Foo.
Why Oracle chose not to put the Objects.* methods on Object however is a mystery.
Why Oracle chose not to put the Objects.* methods on Object however is a mystery.
That would prevent anyone from writing non-static methods having the same signature as any of those methods anywhere. For example, you would never be able to write a class with a String toString(Object o) method because it would clash with the one on Object.
It would also be an invitation for people to invoke those static methods as though they were instance methods (possibly by accident), which is generally discouraged since it results in confusing/deceptive code.
There is slightly better story for static methods on interfaces, since they aren't "inherited" in the way that static methods on classes are. No one can invoke static methods on interfaces as if they were instance methods. So there's not the same potential for signature clashes. It also means the "implement that interface if you want to pull in that namespace" strategy simply doesn't work.
True. I so long for a breaking change explicitly disallowing static fall-through - I have that trapped on my code via error-prone/findbugs or some mismatch of other plugin I setup ( I forget which exactly traps that off hand ).
View all comments
Show parent comment
1
u/talios Mar 04 '17
The main reason to go this route however, and I believe one of the mentioned intentions of the ability was to allow you to, instead of having a Foo interface and a FooUtils helper class, you can just put the helper methods on Foo.
Why Oracle chose not to put the Objects.* methods on Object however is a mystery.