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?
You class should be:
@SecondAnnotation(
version = 1,
inside = @FirstAnnotation(
author = "alessandro"
)
)
public class GeneralClass {
/*
* a generic method
*/
public void method() {
System.out.println("method");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.