This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find All Implementing Classes

 
Mark Fabrizio
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using jdk 1.1.8, is there a way to find all the implementing classes of a specified interface? Really what I'm after is to call a method defined in the interface for all the implementing classes.
Thanks in advance,
-mark-
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the implementing classes in the WORLD, or were you containing your search to some sub-portion thereof?
 
Mark Fabrizio
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just looking for all implementing classes in the package that I am writing.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this method static? If so you can simply call it using the class name

If it isn't static, then your question doesn't make much sense to me. Not only do you need to find the classes that implement the interface, you also need to call the method using objects of said interface. I don't know of anyway to arbitrarily troll memory for instances of a specific class.
Perhaps if you explain the overall problem that you are trying to solve, then we can give you suggestions to help you towards the solution. Off the top of my head, one solution is to keep a list of the instances in one of your classes. Every time a new instance is created and it needs the certain method called, this new instance can register itself with the list of these instances. This is similar to how the event mechanism works in Java.
HTH
Layne
 
Mark Fabrizio
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a static method is what I want to implement.
Thanks for your help, and sorry for my somewhat vague problem description. I haven't programmed in java in a few months and I'm feeling a little rusty.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No prob! I'm glad something in my rambling gave you an idea for a possible solution to your problem.
Keep coding!
Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic