I have a problem with this code. I compile this code using the
command:
c:\> f:\j2se6.0\bin\javac.exe -Xlint:all c:\TestGenerics.java
The result is:
TestGenerics.java:9: warning: [unchecked] unchecked cast
found : TestGenerics<SubClass>
required: SubClass
return (SubClass)this;
^
1 warning
My code runs without any problem, i want to change this code so that
no warning message appear when i compile it, but without any changes
in main method.
public class TestGenerics<SubClass extends TestGenerics> {
public static void main(String[] args) {
new Sub().getSubClass().sub();
}
public SubClass getSubClass() {
System.out.println("1st msg: <method getSubClass()>");
return (SubClass)this;
}
}
class Sub extends TestGenerics<Sub> {
public void sub() {
System.out.println("2nd msg: <method sub()>");
}
}