Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   read java Annotation field values from class (http://www.velocityreviews.com/forums/t868927-read-java-annotation-field-values-from-class.html)

mani 03-01-2012 10:54 AM

read java Annotation field values from class
 
How to read java Annotation field values from reflect class.
I am having a java class file Myclass.java. This file having the
annotation

@interface MyAnnotation {
boolean DuplicateValues();
boolean DuplicateVariables();
}
@MyAnnotation(DuplicateValues = true, DuplicateVariables = true)

I need to get get value of DuplicateValues, DuplicateVariables, that
means true,true from Myclass.class .

markspace 03-01-2012 05:00 PM

Re: read java Annotation field values from class
 
On 3/1/2012 2:54 AM, mani wrote:
> How to read java Annotation field values from reflect class.
> I am having a java class file Myclass.java. This file having the
> annotation
>
> @interface MyAnnotation {
> boolean DuplicateValues();
> boolean DuplicateVariables();
> }
> @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 03-01-2012 06:00 PM

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/wikipedi.../c/cf/Friz.jpg


All times are GMT. The time now is 08:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.