-1

how can I access class variable from my custom annotation in Java language? Is it possible?

@MyAnno
public class MyClass() {
    String name;
    String surname;
    ....
} 

public @interface MyAnno{
 // I want to access MyClass and get the class variable etc name, surname.
}

1 Answers1

1

You can not get the annotated class with plain java. You have to use tool like org.reflections or annotation indexer to get a list of all annotated java.lang.Classes.

Oliver Gondža
  • 3,386
  • 4
  • 29
  • 49
  • Hi, thanks you for answer. I want to create case/data class in java as scala case class and etc. When I printed object to output I don't see hashcode , ı want to display all variable of class and your value to special format. – Alican Akkuş Nov 19 '15 at 22:12
  • Once you have a reference, it will be possible to dump even private fields using reflection. See http://stackoverflow.com/questions/603013/dumping-a-java-objects-properties – Oliver Gondža Nov 20 '15 at 11:10
  • Thanks you for answer again. I understand not possible doing by annotation. I will do with. reflection – Alican Akkuş Nov 20 '15 at 18:40