What methods should go into a java.util.Objects class in JDK 7? (original) (raw)

David M. Lloyd david.lloyd at redhat.com
Tue Oct 6 23:49:23 UTC 2009


On 10/06/2009 06:43 PM, Joe Darcy wrote:

David Holmes - Sun Microsystems wrote:

Hi Joe,

I thought the point that Jason Mehrens was making was that this: + public static String toString(Object o) { + String.valueOf(o); hat Jason Mehrens was making was that this: + public static String toString(Object o) { + String.valueOf(o); + } is actually pointless. Why introduce + } is actually pointless. Why introduce such redundancy when people can just use String.valueOf directly ? Because, IMO, String.valueOf is obscure and hard to find and from its name it is not clear it does null-safe toString on the argument. For example, I didn't know about String.valueOf. It is much clearer what Objects.toString is intended to do.

I for one never thought of it as obscure. Isn't this one of the static methods one must know before taking the SCJP exam? I'm sure it was one of the first methods I learned, back in the day.

This doesn't provide any benefit. I think having the new method be commonly called would be a benefit :-) I don't think having a one-line forwarding method in Objects is that harmful.

Redundancy can be harmful in fact. Now you've got two ways to do the exact same thing; it just makes it a little harder for people to develop and adhere to coding standards, to give one example.



More information about the core-libs-dev mailing list