e.g. with
class Foo {
Integer bar;
}
I wonder why there isn't a language feature that enables me to do
Foo.class.bar //yes, xxx.class returns something of java.lang.Class<T>
to refer to the meta field bar?
I'm reading the Pro JPA 2 Book and it seems to me the canonical metamodel generation is necessary, because this isn't possible in Java.
Note, this is a theoretical question out of curiosity, where I would like to gain some insights, why this feature wasn't implemented.
--- Update ---
To elaborate my question a bit more, consider the example of adding attributes in JPA by the Entity Graph API:
EntityGraph<Foo> g = myEntityManager.createEntityGraph(Foo.class)
g.addAttributeNodes("bar")
There is no formal link (for the compiler / the IDEs) between the string "bar" and Foo´s attribute bar.
Theoretically I wouldn't call class property/field a 'meta' field. Meta-data is assigned to properties/fields through java annotations and this meta-data is accessed through reflection. By doing Foo.class.bar you destroy the whole point of the object-orientation of this beatiful static language. (Or in other words java is not groovy enough to do it))