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

[442 byte] By [AdrianSosialuka] at [2007-11-27 5:02:50]
# 1
Well, the first one uses MyClass both as a parametrized type (the first instance) and as a raw type (the second instance). So it's likely to lead to compiler warnings.
DrClapa at 2007-7-12 10:20:51 > top of Java-index,Core,Core APIs...
# 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

AdrianSosialuka at 2007-7-12 10:20:51 > top of Java-index,Core,Core APIs...
# 3
In your example, Subtype does not extend Base<Subtype>, that's why it does not compile: it does not conform to T extends Base<T>.
stefan.schulza at 2007-7-12 10:20:51 > top of Java-index,Core,Core APIs...
# 4
Yea - now I know. Once you click it seems to be easy and logical :)Cheers,Adrian
AdrianSosialuka at 2007-7-12 10:20:51 > top of Java-index,Core,Core APIs...