Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

A Generics Problem: warning: [unchecked] unchecked cast

  Asked By: Nisha    Date: Aug 25    Category: Java    Views: 933
  

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()>");
}

}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on A Generics Problem: warning: [unchecked] unchecked cast Or get search suggestion and latest updates.




Tagged: