It seems that with Java 7, Objects class is providing a lot of functionality already covered in other parts of the language.
Take toString() for example. The following will produce the same results:
Objects.toString(12);
String.valueOf(12);
In fact, Objects.toString is defined as:
public static String toString(Object o) {
return String.valueOf(o);
}
Say we’re dealing with actual classes. Is one preferred over another?
Objects.toString(o);
o.toString();
What are language designers telling us here? Should we start preferring Objects’s solution instead of what’s already available? What is a long term rationale for something like this?
See the documentation for said class:
So it’s mostly to save you from an additional
nullguard.