I have a problem with understanding Comparable interface in Java. Here is a code:
public class test{
public class Example1 implements Comparable<Example1> {
private int id;
public Example1(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@Override
public int compareTo(Example1 o) {
if (id == o.getId())
return 0;
else if (id > o.getId())
return 1;
else
return -1;
}
}
public class Example2 extends Example1 implements Comparable<Example2> {
public Example2(int id) {
super(id);
}
}
}
When I want to implement Comparable a second time I get an error java.lang.Comparable' cannot be inherited with different type arguments.
Why I'm not allowed to to implement a child class with Comparable interface? How can I resolve this problem? I will be very thankful for answer.