What methods should go into a java.util.Objects class in JDK 7?
Paul Benedict
pbenedict at apache.org
Wed Oct 7 05:52:49 UTC 2009
Thanks Dave. You are exactly right. That implementation is better.
On Tue, Oct 6, 2009 at 11:56 PM, David Holmes - Sun Microsystems
<David.Holmes at sun.com> wrote:
> Paul,
>
> Paul Benedict said the following on 10/07/09 14:44:
>>
>> If you want Objects.toString() to provide value, consider mimicking
>> the functionality from Apache Commons:
>>
>>
>> http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/ObjectUtils.html
>>
>> My biggest complaint about String.valueOf(Object) is that it will
>> actually return "null" for null objects. I can't stand that. If I have
>> no data, I don't want any printable data back. While my preference
>> might be too narrow for the JDK, the second overloaded version of
>> ObjectUtils#toString(String, String) seems like a winner to me. Allow
>> a default String to be provided when it is null:
>
> I can see this might be useful ...
>
>> public static String toString(Object o, String defaultStr) {
>> return (o != null) ? String.valueOf(o) : defaultStr;
>> }
>
> but the implementation would just need to be:
>
> return o != null ? o.toString() : defaultStr;
>
> Cheers,
> David
More information about the core-libs-dev
mailing list