Explanation of two declaration please ...
Hi,
Could anybody tell me what the difference between the two is ?
class MyClass<Textends MyClass>
class MyClass<Textends MyClass><T>>
What could I do with one of them that I couldn't do with the other one
and vice versa ?
Thanks,
Adrian
# 2
Hi,
I have figured out what is what in the following example:
class Base<T extends Base><T>> implements Comparable<T> {
int x;
public Base(int x) {
this.x=x;
}
public int compareTo(T o) {
return x>o.x ? 1 : (x==o.x ? 0 : -1);
}
}
class AnotherSubtype extends Base<AnotherSubtype> {
public AnotherSubtype(int x) {
super(x);
}
}
class Subtype extends Base<AnotherSubtype> {
public Subtype(int x) {
super(x);
}
}
class Proper extends Base<Proper> {
public Proper(int x) {
super(x);
}
}
public class MyTest {
public static void main(String[] args) {
Base<Proper> bp=new Base<Proper>(1);
Base<AnotherSubtype> ba=new Base<AnotherSubtype>(2);
Base<Subtype> bs=new Base<Subtype>(3); // this won't compile unless we change
}//class Base to:
}//class Base<T extends Base> implements Comparable<T>
That explains a lot.
Could you tell something more about these compiler warnings ?
Thanks,
Adrian