java - Read property of an annotation in another -
if declare attribute class way:
@order(value=1) @input(name="login") private string login;
and definition @input
this:
@retention(retentionpolicy.runtime) @target(elementtype.field) public @interface input { string type() default "text"; string name(); string pattern() default ""; string tag() default "<custom:input ordem=''/>"; }
is there way read property value
@order
, use property tag
@input
?
one of ways of reading metadata such annotations,fields , classes reflection.you can use reflection read meta -data of annotation too.
this work if @order
annotation has runtimepolicy of runtime @retention(retentionpolicy.runtime)
note :- annotations class objects.each annotation special type of interface , interfaces treated java.lang.class
objects.
field loginvariaable = .../// login attribute class object using reflection order order = loginvariaable.getannotation(order.class) int ordervalue = order.value(); input inputobject = loginvariaable.getannotation(input.class) string inputname= inputobject.name();
generics helps in getting annotation object without casting annotation object.also ,note annotations implicitly extends java.lang.annotation.annotation
Comments
Post a Comment