lundi 21 septembre 2015

How can I generate a Java factory at compile time?

I have an interface that has been implemented maybe 50 times and my app will keep on evolving with new implementations. These implementations should be loaded depending on their name (which is a constant available in each implementation).

I want to avoid using reflection at runtime (because the reflections lib pulls 3Mb of dependencies and I need to keep my jar as small as possible) and I would also like to avoid having to add an entry to my factory each time an Implementation is added.

So I was wondering: how can I do this automatically at compile time ? I would basically only need to build a map of Implmentation.NAME => ImplmentationConstructor

Thanks





Aucun commentaire:

Enregistrer un commentaire