• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

How can we find the no of classes implementing the particular interface

lets say there is an interface that has a method but the implementation is done in many classes. how can we know the implementation classes
0
chaitu chaitu
Asked:
chaitu chaitu
1 Solution
 
CEHJCommented:
You'd have to iterate them all, load the classes and try casting them to that interface
0
 
girionisCommented:
Do you mean to find out what class implements the interface? You can use the instanceof operator.
0
 
zzynxSoftware engineerCommented:
If you have all possible classes available:

List allPossibleClasses = ...;
Iterator it = allPossibleClasses.iterator();
while (it.hasNext()) {
   Class c = (Class)it.next();
   if (c instanceof BlahblanInterface)
      System.out.println( c.getName() );
}

But, I guess, getting all possible classes is the problem, isn't it?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sciuriwareCommented:
This question is not clear:
1) which of a set of classes implements the interface? > look at the JAVADOC documentation of the set,
2) which of a set .java files does it? > use search with context "implements Interface"
(not safe when implementing multiple intercases.
   You could use grep with "class.*implements.*Interface" on LINUX to overcome this)
If you want to detect this runtime the former answers could be used, but I think that's
a weird time to do it.
I assume you want to know which classes are usable, and that's even before compile time.
<*>
0
 
CEHJCommented:
>>I guess, getting all possible classes is the problem, isn't it?

LOL - obviously not
0
 
zzynxSoftware engineerCommented:
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now