Community
Participate
Working Groups
In 3.5M4, the following snippet public class XX<T> { public void g(Object o) { if (o instanceof XX) o = null; } } reports the use of instanceof XX as inappropriate. In 3.5M3 no warning was issued. Since type arguments cannot be checked, requiring the rewrite to instanceof XX<?> seems very draconian and a major regression on a great deal of existing code.
This is consistent with javac 7 and described at: http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types I agree it is annoying, but at the same time by using XX<?> you make it clear that you didn't miss the fact it was a generic type.
Ok. I guess that one day we'll learn to love this change. In the meantime, with so many formerly warning-free plug-ins now averaging 10 warnings per plug-in, surely yet another selective enable/disable warning option is required in the project/workspace preferences? e.g. a sub-warning of the generic types warning to control warnings on instanceof similar to the sub-warnings for deprecations.
(In reply to comment #1) > This is consistent with javac 7 and described at: > http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types > > I agree it is annoying, but at the same time by using XX<?> you make it clear > that you didn't miss the fact it was a generic type. I do not agree with that. "o instanceof XX" is a test regarding the runtime type of o, which has nothing to do with generics! Moreover, maybe I have not read the document you mention enough deeply, however I read: boolean b = o instanceof List; //same as o instanceof List<?> which sounds to me that "o instanceof List" is the same as "o instanceof List<?>". Apart from the fact that "o instanceof List<?>" sounds quite an "error" to me, however if the two syntaxes are the same, why to issue a warning for the first? At least I think the developer should be given the oportunity to disable this annoying (and useless! What's it useful for?) warning!