Summary: | [1.5][compiler] Unchecked generic type operation always wrong | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Marvin Fröhlich <eclipse> |
Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
Status: | VERIFIED INVALID | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | Olivier_Thomann, satyam.kandula |
Version: | 3.5 | ||
Target Milestone: | 3.6 RC4 | ||
Hardware: | PC | ||
OS: | Linux | ||
Whiteboard: |
Description
Marvin Fröhlich
2010-05-19 08:17:08 EDT
Additionally the quick fixes won't work. Moving the cast to a method or a local variable won't do anything. The same warning will be made there. Hello Marvin, The code snippet below shows what the compiler is warning about : public class C<X> { public void m(Object o) { X x = (X)o; // No exception here as this cast is "unchecked" String s = (String) o; // Exception here as this cast is checked } public static void main(String [] args) { C<String> c = new C<String>(); c.m(new Object()); } } Though both the casts in C#m() "appear" logically to be doing the same thing i.e cast an Object to String, see that only the latter cast throws a ClassCastException. Type variables are not reified at run time (i.e their type information is not completely available at runtime.) Hence neither the compiler nor the VM can arrange to dynamically sanity check the validity of type operations involving them. This is what the compiler is warning about. See that javac issues the same warning with the -Xlint:unchecked command line argument. You can selectively or otherwise suppress this warning as needed. Verified for 3.6RC4 |