Proposal: Sameness operators

Joe Darcy Joe.Darcy at Sun.COM
Thu Apr 2 16:02:56 PDT 2009


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