• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

finding out derived classes

 
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 have an abstract class from which lot of derived classes are going to be created. Now my problem is to identify all the classes which are derived from my abstract class.This is to be done in runtime.

is there any way to do that.

Thanks in advance

-Ramesh
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked the reflection API?
Anyway, I think that with reflection we can fin out information about a class and his superclass but derived classes I don't think so!
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you store their names in some properties file?
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no general way to list all the classes that have been loaded. There is also no general way to list all the classes that are available to be loaded.

When I say "general", I mean applicable to all ClassLoaders. A specific ClassLoader might provide either or both of those facilities. Alternatively, if you know the mechanism used by the ClassLoader (e.g. reading class files and Jars from the classpath), you could make a parallel implementation of this that could discover all the available classes.

If you can get a list of all loaded and/or available classes, the Reflection API will easily allow you to see which one(s) derive from any class or interface.
[ July 16, 2007: Message edited by: Peter Chase ]
 
Ramesh Shankar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks folks

But the catch here is we dont want to use properties file and use the jars in the classpath to identify the same.we need to some generic way or use some simple api calls to acheive this.

Please do keep posted

Thanks
-Ramesh
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can write and use your own ClassLoader, you may have luck. If the ClassLoader is imposed upon you by some frameworks, you can't do that.

Otherwise, you are going to have to face the fact that Java won't do what you want. You'll need to revise your design at a higher level, so you no longer need the facility which simply does not exist.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic