Cyclic annotation element type

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

If the following annotations are specified in different files, javac
(correctly) rejects them:

public @interface Bar {
Baz baz();
}

public @interface Baz {
Bar bar();
}

It seems to me then that the following should also be rejected on the
same grounds:

public class Foo {
public static @interface Bar {
Foo.Baz baz();
}

public static @interface Baz {
Foo.Bar bar();
}
}

However, javac 1.5.0_11 accepts this class. Is there some arcane
scope reason why the above is acceptable, or is javac wrong?
 
M

Mark Rafn

Christopher Benson-Manica said:
If the following annotations are specified in different files, javac
(correctly) rejects them:
Agreed.

It seems to me then that the following should also be rejected on the
same grounds:

public class Foo {
public static @interface Bar {
Foo.Baz baz();
}

public static @interface Baz {
Foo.Bar bar();
}
}

I can't think why javac should accept them. I didn't see anything with a
quick search in bugs.sun.com - if you can't find one, I'd say to file it.
However, javac 1.5.0_11 accepts this class. Is there some arcane
scope reason why the above is acceptable, or is javac wrong?

Is there any way to use such an annotation? I think javac is wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top