raw types warnings and instanceof

Martin Buchholz martinrb at google.com
Sun Nov 2 16:26:24 PST 2008

Hi javac maintainers,

This is a bug report, sort of.

Thanks for adding the raw types warnings, but...

they currently warn about
x instanceof RAW-TYPE
when they probably should not.

It is very common to do

void f (Foo<T> x) {
  if (x instanceof Bar) {
    Bar<T> y = (Bar<T>) x;

The workaround is to do:

void f (Foo<T> x) {
  if (x instanceof Bar<?>) {
    Bar<T> y = (Bar<T>) x;

but the addition of <?> adds noise without providing any safety.


More information about the compiler-dev mailing list