Reputation: 1418
I'm trying to code, for fun, a class that use an annotion with another annotation inside, but I don't understand how to code.
@interface FirstAnnotation {
String author();
}
public @interface SecondAnnotation {
FirstAnnotation inside();
int version();
}
@FirstAnnotation(
author = "alessandro"
)
@SecondAnnotation(
version = 1,
inside = /*Compilation code: what code? FirstAnnotation, this??*/
)
public class GeneralClass {
/*
* a generic method
*/
public void method() {
System.out.println("method");
}
}
What I have to put in row with string Compilation code, as reference to actual value of FirstAnnotation in the class?
Upvotes: 0
Views: 4205
Reputation: 60094
You class should be:
@SecondAnnotation(
version = 1,
inside = @FirstAnnotation(
author = "alessandro"
)
)
public class GeneralClass {
/*
* a generic method
*/
public void method() {
System.out.println("method");
}
}
Upvotes: 7