Cannot get complex annotation to compile

I am trying without success to get a complex annotation to compile. The annotation is defined similar to:

@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ComplexAnnotation {
MyEnum scope();
String[] keys();
}

and it is placed on a few classes such as:

@ComplexAnnotation(
scope = MyEnum.PUBLIC,
keys = {
MyString.STATIC_STRING
}
)

While an annotated class in the same package as MyString DOES compile, when I place the same exact annotation on a class in another package, I get the following error:

Error:Error:line (47)annotation ComplexAnnotation is missing ]]>

Note that I've also tried replacing the (public static final) STATIC_STRING with an inline string, i.e. "test...", and that DOES NOT work either.

I am baffled at this point. I've tried this on Java 1.5 Mac, and Windows (latest versions of java available). At this point I'm thinking I've either made a really STUPID syntax error, or, there might be a bug in IDEA. Does anyone have any clues?

Thank You,
Eric

1 comment

ARGH! Here is what the problem was. The file containing my custom defined annotation had static variables and a static class included in it. This type of thing works for a normal 'interface', but for a '@interface' you evidently can't have any other code in the file. For example,

public @interface MyAnnotation {

// this static var is not supported in an annotation definition
public static final String MY_STRING = "text...";

public String value();

// this static class is not supported in an annotation definition
pubilc static class Utility {
pubilc static void testMethod() {
}
}

}

no workie -- and the compiler doesn't give you a useful error message! Hopefully others won't waste a whole day trying to figure this out.

- Eric

0

Please sign in to leave a comment.