Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6500912

Compiler fails to reject program involving method call on raw type (Constructor.getAnnotation)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • tools
    • None
    • generic
    • generic

      The compiler fails to reject this program:

      import java.lang.annotation.Annotation;
      import java.lang.reflect.Constructor;
      public class X {
        void bar(Constructor constructor, Class<Ann> ann) {
          constructor.getAnnotation(ann).message(); // Should fail
        }
      }
      @interface Ann {
        String message();
      }

      class Y {
        void bar(MyConstructor constructor, Class<Ann> ann) {
          constructor.getAnnotation(ann).message(); // Should fail
        }
      }

      interface Z {
        <T extends Annotation> T getAnnotation(Class<T> c);
      }
      class MyAccessibleObject implements Z {
        public <T extends Annotation> T getAnnotation(Class<T> c) { return null; }
      }
      class MyConstructor<V> extends MyAccessibleObject {
        public <T extends Annotation> T getAnnotation(Class<T> c) { return null; }
      }

            ahe Peter Ahe
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: