You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it is same as the other annotation except it provides a shorthand for specifying value of the member.
you can simply specify the value for that member without specifying the name.
but the member name must be value, it will not work for any other names
importjava.lang.annotation.Retention;
importjava.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface Description{
Stringvalue();
}
classMain{
@Description("This is the description for this method")
publicstaticvoidm(){}
publicstaticvoidmain(String[] args){
try{
System.out.println(Main.class.getMethod("m").getAnnotation(Description.class)); // @Description("This is the description for this method")
}catch (Exceptionex){
System.out.println(ex.getMessage());
}
}
}