Community
Participate
Working Groups
Build Identifier: 20090920-1017 If I have a class like this class C<T extends SomeClass> {} and I have enabled warnings for "Usage of raw type" and I use the class as follows ############# C c = getACInstanceFromSomewhere(); ############# a warning will be produced. I would like to exclude all classes (not to be warned about), that declare a generic type like this. class C2<T2 extends Something> {} instead of just class C3<T3> {} If I restrict the generic type parameter to subclasses of something, it is clear, that if used untypedly, it is treated as it is typed with <Something> (the base type). Otherwise people will either not use this warning and will hence miss a lot of potential bugs or will "enrich" the code with <?> parameters or add SupperssWarnings annotations, which doen't make the code better, but eliminates the warning. Reproducible: Always
(In reply to comment #0) [...] > If I restrict the generic type parameter to subclasses of something, it is > clear, that if used untypedly, it is treated as it is typed with <Something> > (the base type). These matters are dictated by the language specification and the compiler is not at liberty to treat the raw type C as though it were C<Something>. Per section 5.1.9 Unchecked Conversion of JLS, an expression of type C when converted to C<Something>, must generate an unchecked warning. This is not possible if C were treated to be C<Something> in the first place as you propose in: class C<T extends X> { C c1 = new C(); C<X> c = c1; // MUST generate a warning here. } class X { } The unchecked warnings indicate potentially serious problems. OTOH the raw type usage warning is intended for folks who want to generify their code and need the help of the compiler in locating all places where raw types are used and as such the situations you cite are good candidates for the warnings. Based on project needs, these warnings can be suppressed wholesale or individual basis using annotations.
Verified for 3.6RC4