score:0

do you use any framework or you write your own? i answered similar question about guice here. you can use it without guice as well: instead of module you will have your factory, which you need to initialize from somewhere, and during initialization, you will fill your map using reflection

in general i think it is the easiest approach. alternatively, you can write macros, which just replaces part of reflective initialization, but not sure that it will give you some profit (if i understand your question right, this initialization will happen just once at startup).

i do not see how scalameta can help you? probably, only in case if all your implementations are in source tree available to you, so you can analyze it and generate initialization (similar to macros)? probably, this would add such plus as easier search for implementation, but will add minus: will work only on implementations in your sources.

your example of compile-time optimization is not applicable. in your example, you talk about compile-time constant (even with arithmetic it could be a problem, see this comment), but in your question you need specific run-time behavior. so compile time could be only code generation from macros or based on scalameta from my point of view.


Related Query

More Query from same tag