Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11781

dynamic cdi with @Any

$
0
0

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;    }}

Viewing all articles
Browse latest Browse all 11781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>