j.u.Objects follow-up: variations on Object -> String methods
Joseph D. Darcy
Joe.Darcy at Sun.COM
Thu Oct 8 12:12:11 PDT 2009
During the vigorous discussion of what Objects.toString(Object) should
be defined to do, a number of alternatives were suggested:
public static toString(Object a, String default) // return default if (a
== null) else a.toString()
public static toDefaultString(Object a) // return the string
Object.toString returns if not overriden, what about null?
public static toDebugString(Object a) // reflectively return an
informative representation of the argument
I can accept the utility of toString(Object a, String default) and will
include it in the next round of j.u.Objects updates.
The functionality of toDefaultString is included in Apache commons under
the name of "identityToString," returning null for a null argument.
From a quick Google code search, this methods doesn't seem to be widely
called and I'm not yet convinced it's worthwhile to add this method to
I think I could be convinced that a reflection-based toDebugString was
useful enough to include in the platform. However, someone would have
to contribute the specification and a robust implementation.
More information about the core-libs-dev