Java Mailing List Archive

http://www.gg3721.com/

Home » eclipse-plugin-dev.groovy »

[groovy-eclipse-plugin-dev] getAnnotation error?

Jason Cheatham

2012-09-24

Replies: Find Java Web Hosting

Author LoginPost Reply


From: Jason Cheatham <smellycalf@yahoo.com>;
To: <eclipse-plugin-dev@groovy.codehaus.org>;
Subject: getAnnotation error?
Sent: Mon, Sep 24, 2012 6:07:25 PM

I'm using groovy eclipse 2.7.1 and I get the correct output with the first class and an error with the second. Is this an issue with Groovy?

import groovy.transform.CompileStatic;
import java.lang.reflect.Field;
@CompileStatic
class AnnotationCompileStatic {
public static boolean annotationCheck(Field field) {
Override annotation = field.getAnnotation(Override.class);
return (annotation != null);
}
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Output:
false
false
false
false
false
false
false

Copy same main method to a class in the same package and you get an error:

import java.lang.reflect.Field;
class AnnotationCompileStaticTest {
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Caught: java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
at AnnotationCompileStatic.annotationCheck(AnnotationCompileStatic.groovy:17)
at AnnotationCompileStatic$annotationCheck.call(Unknown Source)
at AnnotationCompileStaticTest$_main_closure1.doCall(AnnotationCompileStaticTest.groovy:11)
at AnnotationCompileStaticTest.main(AnnotationCompileStaticTest.groovy:10)
©2008 gg3721.com - Jax Systems, LLC, U.S.A.