Proposal: Sameness operators

Joe Darcy Joe.Darcy at Sun.COM
Thu Apr 2 19:09:37 PDT 2009


Tim Keith wrote:
> I would like to suggest calling the class java.lang.Objects, similar
> to java.util.Collections and java.util.Arrays.

Since this would be a utility class, I thought it would be better placed 
in java.util rather than java.lang.

> And it would be handy to also have in there a null-safe static method
> to help in implementing hashCode:
>     public static int hashCode(Object o) {
>         return o == null ? 0 : o.hashCode();
>     }

I've added this suggestion to the Sun bug.

Thanks,

-Joe


> -- Tim
> 
> On Thu, Apr 2, 2009 at 4:02 PM, Joe Darcy <Joe.Darcy at sun.com> wrote:
>> Reinier Zwitserloot wrote:
>>
>> [snip]
>>
>>> public static void is(Object x, Object y) {
>>>      if ( x == null ) return y == null;
>>>      return x.equals(y);
>>> }
>>>
>>> public static void is(Object x, int y) {
>>>     // Yes, you'd need a few gazillion is methods to cover all the
>>> primitives on either side, but 1 static import will grab all of them
>>> }
>>>
>>> ... loads more is methods
>>>
>>>
>>> Then same with lt, gt, le, ge.
>>>
>>> Then you could write:
>>>
>>> if ( is(a, b) ) {
>>>    //doStuff
>>> }
>>>
>>> Which is a small improvement.
>>>
>>> Add an ability to specify 'as infix' in static imports, and you have
>>> pretty much what we all want without backwards compatibility issues:
>>>
>>> import static java.lang.Equality.is infix;
>>>
>>> if ( a is b ) {
>>>    //do something
>>> }
>>>
>>> I'd consider that a large improvement.
>> Yes, in JDK 7 I'd like to see
>>
>>     6797535 Add shared two argument static equals method to the platform
>>     http://bugs.sun.com/view_bug.do?bug_id=6797535
>>
>> addressed in the platform.  I was thinking putting it in a place like a
>> new utility class java.util.Object.
>>
>> -Joe
>>
>>
> 




More information about the coin-dev mailing list