9

I understand the general differences between the concepts of

  • reflection (done at runtime using Class, Method, Field, Annotation, ...), and
  • mirroring (done during annotation processing using TypeMirror, TypeElement, ...).

But can someone please compare the two concepts in-depth (or point me to a resource, where it is done)?

For instance, which concept offers what kinds of information that the other does not offer...

Thank you.

java.is.for.desktop
  • 10,748
  • 12
  • 69
  • 103

2 Answers2

5
  • Reflection classes are used to represent the classes of objects in a running JVM. Reflection is a very old concept that has been present in Java since the very beginning. As such, it is a bit clunky in some areas, having been extended to accomodate new language constructs (especially generics).
  • The classes in javax.lang.model are used to work with Java source code. They were designed when Generics already existed and can (and have to) support them much more extensively, since they are used before type erasure happens.
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • Thank you. But, as I mentioned, the general concepts are known, and I was hoping for an in-depth analysis. BTW, I think the statement that reflection has been extended to support generics is wrong, as you mentioned by yourself, they are erased during runtime. – java.is.for.desktop Dec 16 '10 at 20:34
  • Oh, I see, by saying that java.lang.reflect was extended for generics, you probable are referring to `java.lang.reflect.TypeVariable`. Hmm, never used it, will inform myself about it... – java.is.for.desktop Dec 16 '10 at 20:44
  • 2
    @java.is.for.desktop: the type parameters of objects are erased, but the type parameters in field, method and class definitions are not. – Michael Borgwardt Dec 16 '10 at 21:08
1

I think you will find the answer in this paper.

Yardena
  • 2,837
  • 20
  • 17
  • 2
    Thanks for the paper but it's really hard to read since it's intended for the research audience. It would be great if you can briefly describe it from a technical perspective. – Amir Moghimi Aug 02 '11 at 01:11