Snippets

Ettar Java - equals

Created by Ettar
public class TestObject {
    int hoehe;
    int breite;

    public TestObject(int hoehe, int breite){
        setBreite(breite);
        setHoehe(hoehe);
    }

    @Override
    public boolean equals(Object o){
        TestObject other;
        if(o!=null&&o instanceof TestObject){
            other = (TestObject) o;
            if(other==this){
                return true;
            }
            else if(other.getHoehe()==this.hoehe&&other.getBreite()==this.breite){
                return true;
            }
        }
        return false;
    }

    public int getHoehe() {
        return hoehe;
    }

    public void setHoehe(int hoehe) {
        this.hoehe = hoehe;
    }

    public int getBreite() {
        return breite;
    }

    public void setBreite(int breite) {
        this.breite = breite;
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.