// Collection of code snippets by Arne Vajhøj
// posted to eksperten.dk, usenet and other places (2002-now)
import java.util.ArrayList;
import java.util.List;
public class Wrap {
public static void main(String[] args) {
List lst = new ArrayList();
lst.add(new B("X", "Y"));
lst.add(new A("Z"));
System.out.println(lst.contains(new B("X", "Y")));
System.out.println(lst.contains(new A("X")));
System.out.println(lst.contains(new B("X", "Z")));
System.out.println(lst.contains(new A("W")));
}
}
class A {
private String a;
public A(String a) {
super();
this.a = a;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
@Override
public int hashCode() {
return a.hashCode();
}
@Override
public boolean equals(Object o) {
if(o instanceof A) {
return a.equals(((A)o).a);
} else {
return false;
}
}
}
class B extends A {
private String b;
public B(String a, String b) {
super(a);
this.b = b;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}