Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

reflection

Thread view: 
marcin.strugala@gmail.com - 04 Feb 2008 20:10 GMT
Hello,
could you please give me some hint how to retreive information about
inheritance of class? Is it possible to use reflection to this
purpose? I would like to collect all information about classes i.e.
all class' fields and its base class (if the one exists). I know how
to discover information about class' fields using reflection but I
have no idea how to use this mechanism to collect information about
class' inheritance.

Thanks in advance
Arne Vajhøj - 04 Feb 2008 20:45 GMT
> 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
Mike  Schilling - 04 Feb 2008 23:33 GMT
> 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.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.