> could you please give me some hint how to retreive information about
> inheritance of class? Is it possible to use reflection to this
[quoted text clipped - 3 lines]
> have no idea how to use this mechanism to collect information about
> class' inheritance.
I have never used it myself, but Class has a getSuperclass method - it
sound as if it will do it.
Arne
> Hello,
> could you please give me some hint how to retreive information about
[quoted text clipped - 4 lines]
> have no idea how to use this mechanism to collect information about
> class' inheritance.
Start with a java.lang.Class object, obtained either from an instance
int.getClass()
or a name
Class.forName(name);
On the Class you'll find methods to get the superclass, the interfaces
implemented, the fields, the methods, etc. The classes that represent the
other objects used in reflection (Method, Field, etc.) are found in
java.lang.reflect. Read the documentation carefully to see exactly what
each method returns, for instance
Class.getFields()
-- all *public* methods, including those inherited from superclasses
Class.getDeclaredFields()
-- all methods declared *by this class*
The facility is quite powerful, and, except for method bytecode, gives you
almost everything you'd get from opening up the classfile and reading it
yourself. (The one thing I've wanted but couldn't get is whether the field
is a compile-time constant or not. This information is in the classfile,
but AFAICT not made available via reflection.)