1

I know how to using Reflection determine the super class of a class. So if I had a game, and I had a map editor, and I wanted it to have a panel with a button to select select any type of Solid that can be added to the game and add it, I could theoretically use reflection to look through all the classes in my game and see which ones have the super class "Solid", and then add a button to the panel. The only thing that prevents me from doing this is that I need a list of all classes to search through, is there a way I can get that?

csga5000
  • 4,062
  • 4
  • 39
  • 52

1 Answers1

2

You probably want the Java Service Provider Interface. It gets around this problem by having you list the implementing "plug-in" (provider) classes in the jar manifest. You then use ServiceLoader to ask for all of the available implementations, and you only have to use Class.forName. Here's another useful overview.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • Thanks, I'm looking into this. If I get it to work, I'll mark as answer. Some quick example code would be really nice, and I'd give a 1up. – csga5000 Sep 02 '13 at 17:49
  • Just look at the docs on `ServiceLoader`. For all of the classes implementing your interface, you'll just want `ServiceLoader.load(MyInterface.class).iterator()`. – chrylis -cautiouslyoptimistic- Sep 03 '13 at 04:32