How to implement Box.equals
    Maurizio Cimadamore 
    maurizio.cimadamore at oracle.com
       
    Fri Aug 14 14:33:13 UTC 2015
    
    
  
Peter Levart posted quite an interesting approach while back:
http://cr.openjdk.java.net/~plevart/misc/valhala-hacks/javany-webrev.01/src/java.base/share/classes/java/util/Any.java.html
Maurizio
On 14/08/15 15:15, Boaz Nahum wrote:
> How can one implement something simple as Box.eqauls
>
> I tried:
>
> public class PSupport {
>      static boolean equals(boolean x, boolean y) { return x == y;}
>      static boolean equals(int x, byte y) { return x == y;}
>      static boolean equals(char x, char y) { return x == y;}
>      static boolean equals(short x, short y) { return x == y;}
>      static boolean equals(int x, int y) { return x == y;}
>      static boolean equals(long x, long y) { return x == y;}
>      static boolean equals(float x, float y) { return x == y;}
>      static boolean equals(double x, double y) { return x == y;}
>      static boolean equals(Object x, Object y) { return Objects.equals(x, y); }
>
> }
>
>
> public class Box<any X> {
>
>      private final X x;
>
>      public Box(X x) { this.x = x;}
>
>      @Override
>      public boolean equals(Object o) {
>          if (this == o) return true;
>          if (o == null || getClass() != o.getClass()) return false;
>
>          Box<X> box = (Box<X>) o;
>
>          return PSupport.equals(x, box.x);
>      }
>
> }
>
> But it doesn't accept PSupport.equals(x, box.x);
>
> Thx
>
> Boaz
    
    
More information about the valhalla-dev
mailing list