Re: read java Annotation field values from class
markspace wrote:
mani wrote:
[Please explain] How to read java [sic] Annotation field values from reflect class.
I am having a java [sic] class file Myclass.java.
That's not a class file, that's a source file.
This file having the annotation
@interface MyAnnotation {
boolean DuplicateValues();
This attribute name violates the naming conventions.
boolean DuplicateVariables();
This attribute name violates the naming conventions.
}
@MyAnnotation(DuplicateValues = true, DuplicateVariables = true)
I need to get get value of DuplicateValues, DuplicateVariables, that
means true,true from Myclass.class .
When you define the annotation, you have to add another annotation that tells
the compiler to insert the annotation into the bytecode. The default I believe
is that the annotation is only available to the compiler.
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
boolean DuplicateValues();
boolean DuplicateVariables();
}
<http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html>
<http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html>
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg