• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting the Inherited property of a given class

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to find out the inherited property (say, inherited method) of a given class.
I have tried using relfection, but the problem is, if the class imports another class
, it doesn't work. For example, say we have a class file named ExampleA.Class.






Would you please tell me the solution?
Also, how can it be done in case of the classes contained in jar file?

Thanks in advance.
Best Regards,


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"getMethods" only returns public methods, as its javadocs specifically mention. You can get all methods of a class by using "getDeclaredMethods", but not inherited ones. So you will need to obtain a Class object for all super classes, and call getDeclaredMethods on those. The "getSuperclass" method helps with that.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note that your class name is not ExampleA, but Example.ExampleA. You need to include the package name when using Class.forName.
 
Jowel Hasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your valuable suggestions.
In fact, i wanted to fetch the class from a Jar and tried to use reflection to get the inherited property. Here, the class (in this example, AnotherPackage.ExampleB, which is also in the jar;) imported by the given class generates the problem and a ClassNotFoundException is thrown. (It works fine if there is no such import statement.)

What can be done in this situation?
Thank you very much for your cooperation & time.

Best Regards,


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic