read java Annotation field values from class

Discussion in 'Java' started by mani, Mar 1, 2012.

  1. mani

    mani Guest

    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 .
    mani, Mar 1, 2012
    #1
    1. Advertising

  2. mani

    markspace Guest

    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>
    markspace, Mar 1, 2012
    #2
    1. Advertising

  3. mani

    Lew Guest

    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
    Lew, Mar 1, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Pilcher

    Check class file for annotation

    Ian Pilcher, Jan 23, 2006, in forum: Java
    Replies:
    6
    Views:
    833
    Ian Pilcher
    Jan 24, 2006
  2. pek
    Replies:
    2
    Views:
    1,054
  3. Tom Anderson
    Replies:
    1
    Views:
    320
    Tom Anderson
    May 10, 2009
  4. mani
    Replies:
    1
    Views:
    280
  5. Sound
    Replies:
    2
    Views:
    430
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page