0

What I would like to do is loop through all of the classes that are extending a class i have called Cmd.

For instance, what I'd like to be able to do is something like this:

for (Class<?> c : classesExtendingSuperclass) {
    cmds.put(c, c.getName());
}

Thanks.

Edit: I can't use reflections in my project, if I do it will complicate everything when using the program. I can't use Reflections due to the performance downsides in the project.

Banjo226
  • 23
  • 4
  • Are the performance implications worth more to you than the time it would take to develop and test your own implementation of it, along side the actual *use* of it? – Makoto Dec 20 '15 at 06:48
  • @Makoto Yes, the performance matters. This is for bukkit (minecraft server software) and reflections is known to lag and have performance issues with the software, which is something I don't want. – Banjo226 Dec 20 '15 at 06:51
  • Honestly, this smells a bit like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Could you explain what your intention is with this code? Perhaps you'd get a better answer instead of it being confused for a generic one. – Makoto Dec 20 '15 at 06:52

1 Answers1

0

If I have understood your question correctly , I think this is what you are looking for :

Reflections reflections = new Reflections("com.mycompany");    
Set<Class<? extends MyInterface>> classes = reflections.getSubTypesOf(MyInterface.class);
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
  • I can't use reflections in my project, if I do it will complicate everything when using the program. – Banjo226 Dec 20 '15 at 06:39
  • @Banjo226 It's not Java's class, note that it's the `Reflections`. – Maroun Dec 20 '15 at 06:43
  • I think that OP should mention that it's a 3rd party library. – Maroun Dec 20 '15 at 06:43
  • I know its not part of the JDK, and I know its a library. What I was saying is I can't use Reflections due to the performance downsides for it in the project I am doing. – Banjo226 Dec 20 '15 at 06:45