Java:
public boolean equals(Object that) {
if (this == that)
return true;
if (!(that instanceof Vec))
return false;
Vec other = (Vec) that;
if (size != other.size)
return false;
for (int i = 0; i < size; i++) {
if (!elems[i].equals(other.elems[i])) {
return false;
}
}
return true;
}
Warum wird hier überprüft, ob that eine Instanz vom Typ Vec ist?
Es wäre doch viel einfacher, wenn man als Parameter ein Vec anstatt ein Object übergibt.
Dann bräuchte man auch nicht mehr das instanceof.