In our Java EE application, we process different file types. But instead of injecting all types as
@Any@Injectprivate Instance<FileHandler> handler
We do it with a big switch. All handler to extend from FileHandler, it's a abstract class, not an interface. Is there a way to make it generic? From what I can see with Instance, you still have to pass the class file of the implementation you wanna use.
@Injectprivate XmlHandler xmlHandler;@Injectprivate CsvHandler csvHandler;public void method(String fileType) { switch (fileType) { case "xml": xmlHandler.handle(); break; case "csv": csvHandler.handle(); break; }}