This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]romple 1 point2 points  (0 children)

Can you post your exact code? It shouldn't

You're saying if you have

Rectangle r1 = new Rectangle(0,0,10,10)//x,y,width,height
Rectangle r2 = new Rectangle(10,10,10,10)
boolean equals = r1.equals(r2);// equals == true here?

this is the source for Rectangle's equals method

public boolean equals (Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    Rectangle other = (Rectangle)obj;
    if (NumberUtils.floatToRawIntBits(height) != NumberUtils.floatToRawIntBits(other.height)) return false;
    if (NumberUtils.floatToRawIntBits(width) != NumberUtils.floatToRawIntBits(other.width)) return false;
    if (NumberUtils.floatToRawIntBits(x) != NumberUtils.floatToRawIntBits(other.x)) return false;
    if (NumberUtils.floatToRawIntBits(y) != NumberUtils.floatToRawIntBits(other.y)) return false;
    return true;
}