JDK 8 reflection changes (compared to JDK 7)

Pavel Bucek pavel.bucek at oracle.com
Tue Jan 28 02:40:43 PST 2014


Hi all,

I hope this is correct mailing list - if not, please feel free to point 
me to different one.

Consider following code:

     @Retention(RetentionPolicy.RUNTIME)
     @Target(ElementType.METHOD)
     @interface C { }

     abstract class A<T> {
         public abstract void method(T arg);
     }

     class B extends A<String> {
         @Override
         @C
         public void method(String arg) { }
     }

     public static void main(String[] args) {
         for(Method m : B.class.getMethods()) {
             if(m.isAnnotationPresent(C.class)) {
                 System.out.println(m);
             }
         }
     }

When executed on JDK8 (1.8.0-ea-b124), it prints out two methods:

public void 
org.glassfish.tyrus.test.standard_config.GenericClientEndpointTest$B.method(java.lang.String)
public void 
org.glassfish.tyrus.test.standard_config.GenericClientEndpointTest$B.method(java.lang.Object)

result on JDK7 (just one method):

public void 
org.glassfish.tyrus.test.standard_config.GenericClientEndpointTest$B.method(java.lang.String)

Why is the method with Object param added to result set? And why it does 
have @C annotation declared? If this is intentional, is there any way 
how I could reliably filter out method with Object as parameter to get 
same result as on JDK7?

Thanks and regards,
Pavel



More information about the jdk8-dev mailing list