Stop show with sound -- Keyboard shortcut: 'x'  Next slide in show -- Keyboard shortcut: 'n'  2 minutes, 23 secondsObjekt-orienteret programmering i Java, del 1 - slide 26 : 27

Mønster for equals i Java 

Redefinitioner af equals bør følge et bestemt mønster
 

class EqualsDemo {

    private int state; 

    public EqualsDemo (int state){
	this.state = state;
    }

    public boolean equals(Object other){
	int thisState = this.state;
        int otherState = ((EqualsDemo) other).state;
	if (other instanceof EqualsDemo)
	    return thisState == otherState;
        else return false;
   }

}