Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Annotations are not working in Groovy classes

I have Groovy-Eclipse for Juno but my Groovy classes are not able to recognize any Annotations. I am getting Groovy:class Translation is not an annotation in @Translation.Or Groovy:class Override is not an annotation in @Override For example:

import somewhere.Translation
@Translation(translationContext = TranslationContext.SOMETHING)
class SOMECLASS extends SOMETHING {

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Translation {

Here all the annotations @Target,@Retention and @interface are compiling fine for Translation
I have all the jars included in my project lib. What am I missing here?

Upvotes: 1

Views: 3103

Answers (3)

virtuemaster
virtuemaster

Reputation: 105

I have faced the same issue. My Eclipse IDE underlines the annotations but the code works fine! Just try to run it. That's it for me. Hope that's it for you as well)

Upvotes: 0

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

Looks like you have your project/workspace configured for Java 1.4 or earlier. Annotations are not being recognized since the source level doesn't allow them.

Go to Project -> Properties -> Java Compiler. Enable project settings and set the compliance level to 1.5 or later.

Upvotes: 1

Zasz
Zasz

Reputation: 12538

  • Did you import import java.lang.annotation.*; ?
  • Is translationContext defined like a method in the @interface ?
  • Is the correct Translation in the classpath, and no duplicates are there.

This code works for me in the groovy console :

@Translation    
class A{
def meth = { print "HzzzI" }
​}

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)
public @interface Translation {
} 

A a = new A();
a.meth()

Upvotes: 0

Related Questions