|
|
|
|
|
frage editiert...
– Schnotzeck 04.02.2011
|
||
|
Wie unten schon erwähnt: Entweder du verdrahtest nun hart deine Feldvergleiche mit equals (=beste performance) oder Du machst es mit Reflection. Das kann aber beliebig komplex werden.
Dort wurde sowas wohl schon mal implementiert: http://jajatips.blogspot.com/2008/10/using-reflections-for-test-equals.html – CRegenschein 04.02.2011
|
|
|
|
|
|
|
|
|
|
|
class A {
private String x;
private B b;
public A (String x, B b) {
this.x = x;
this.b = b;
}
@Override
public boolean equals(Object o) {
boolean equals = false;
if (o instanceof A) {
A that = (A) o;
equals = this.x.equals(that.x) && this.b.equals(that.b);
}
return equals;
}
@Override
public int hashCode() {
return this.x.hashCode() * this.b.hashCode();
}
}
public class B {
private String y;
public B (String y) {
this.y = y;
}
@Override
public boolean equals(Object o) {
boolean equals = false;
if (o instanceof B) {
B that = (B) o;
equals = this.y.equals(that.y);
}
return equals;
}
@Override
public int hashCode() {
return this.y.hashCode();
}
}|
|
|
|