"Thomas Singer" wrote :

> PS: Couldn't the equals default implementation not ensured with a simple
> Live template? Lets say, you expand "eq" to a full blown equals method:
>
>    public boolean equals(Object obj) {
>      if (obj == null || obj.getClass() != getClass()) {
>        return false;
>      }
>
>      return |
>    }
>

I don't know the full - and hidden - power of Live Templates,
but a full blown equals() requires more than what you suggest.


For this very simple class
   public class MyClass {

      private String  s ;
      private int     i ;
      private boolean b ;
      private float   f ;
      private char    c ;
  }

equals would look like this ;

    public boolean equals (Object o)
    {
        if (this == o)                    return true  ;
        if (! (o instanceof MyClass ))  return false ;
        final MyClass obj = (MyClass) o;
        return
                obj.s  .equals(  this.s )
            &&  obj.i  ==  this.i
            &&  obj.b  ==  this.b
            &&  obj.Float.floatToIntBits(f)  ==
this.Float.floatToIntBits(f)
            &&  obj.c  ==  this.c    ;
    }



For info, here is the hashCode() for this class.
(Based on "Effective Java"'s recipe)

    public int hashCode ()
    {
        int result = 17;
        result   = 37 * result + s.hashCode() ;
        result   = 37 * result + (int)i ;
        result   = 37 * result + (b ? 0:1) ;
        result   = 37 * result + Float.floatToIntBits(f);
        result   = 37 * result + (int)c ;
        return result  ;
    }


It's so repetitive and cumbersome,  I wrote a doclet to generate this code
for me.
I'm not a trained monkey

Did you notice ? This is the old "canonical objects generator, please"
thread coming back.

Alain


_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features

Reply via email to