Community
Participate
Working Groups
I'm using eclipse-SDK-I20041201-win32.zip. Runtime retention policy does not seems to be implemented in the compiler. In the provided test null should not be returned from getAnnotation() method. The following line is printed: "value = null" When compiled by JDK 1.5, the following line is printed: "value = @test.Attr(tst=-1)" Also class files are different "RuntimeVisibleAnnotations" class file attribute is used by JDK 1.5 and "RuntimeInvisibleAnnotations" by Eclipse. Note: unsafe cast in sample is done to avoid bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=80012. ------------------ test/Attr.java ------------------ package test; import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface Attr { public int tst() default -1; } ------------------ test/TestCls.java --------------- package test; import java.lang.annotation.Annotation; @Attr public class TestCls { public static void main(String args[]) { Object e = TestCls.class.getAnnotation((Class<Annotation>)(Class)Attr.class); System.out.println("value = "+e); } }
Meta-annotations are not supported yet. For now, all annotations are generated with the default retention policy which is CLASS. They end up as RuntimeInvisibleAnnotations in the .class file.
*** Bug 80012 has been marked as a duplicate of this bug. ***
I suggest making all annotations runtime visible in the next integration version by default if support for meta-annotations is not planned for it yet. If it is done, annotations will become usable for tools that need annotations on the classes in runtime until they are completely supported.
Fixed and released in HEAD. Regression tests added AnnotationTest.test079-test084.
*** Bug 80010 has been marked as a duplicate of this bug. ***
Verified for 3.1 M4 using build I200412142000.