equals


<aside> ๐Ÿช…

์„ค๋ช…


์˜ˆ์ œ


<aside> ๐ŸŽฝ

package test;

import java.awt.*;

public class RectangleMain {
    public static void main(String[] args) {
        Rectangle rect1 = new Rectangle(100,20);
        Rectangle rect2 = new Rectangle(100,20);
        System.out.println(rect1 == rect2);
        System.out.println(rect1.equals(rect2));
    }
}
-------------------------------------------------
package test;

import java.util.Objects;

public class Rectangle {
    private int height;
    private int width;

    public Rectangle(int height, int width) {
        this.height = height;
        this.width = width;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Rectangle rectangle = (Rectangle) o;
        return height == rectangle.height && width == rectangle.width;
    }
}

์ถœ๋ ฅ
false
true

</aside>