Play audio slide show -- Keyboard shortcut: 'x'  Lecture overview -- Keyboard shortcut: 'u'  Previous page: Lighed i Java -- Keyboard shortcut: 'p'  Next page: Emnet fortsættes i en efterfølgende lektion [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home  Play sound for this slide -- Keyboard shortcut: 'y'    Objekt-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;
   }

}