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.
Source: stackoverflow.com
Related Query
- Initializing the factory at compile time
- How to get the name of a case class field as a string/symbol at compile time using shapeless?
- Decoding JSON values in circe where the key is not known at compile time
- sbt-buildinfo plugin: How can I add the java version in effect at compile time to the generated BuildInfo.scala?
- How to get the name of a class as a string literal at compile time using shapeless?
- In Scala Reflection, is the compile time universe accessible?
- Do I need to re-use the same Akka ActorSystem or can I just create one every time I need one?
- How to get the current date without time in scala
- Scala project won't compile in Eclipse; "Could not find the main class."
- How do I declare a constructor for an 'object' class type in Scala? I.e., a one time operation for the singleton
- Add a compile time only dependency in sbt
- Scheduling a task at a fixed time of the day with Akka
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Extracting and accessing fields at compile time in Scala 3
- How to measure and display the running time of a single test?
- Scala - Enforcing size of Vector at compile time
- When to use companion object factory versus the new keyword
- How to get the class of a singleton object at compile time?
- Mere presence of implicit conversion makes the program compile despite never being applied
- Functional Tests in Play 2.4.6 when using compile time DI
- How to profile the time spent for a task in SBT
- Scala compile time check for location of constructor calls
- What is the fastest way to compile Scala files using maven?
- scala spec2 I am Unable to create a test that uses must be_== and failure at the same time
- How to modify previous line in REPL - scala to modify the typing errors to save time compare to entering each line using up/down arrows
- Extremely slow compile time with SBT auto-reload using play! and scala-js
- Akka: what is the reason of processing messages one at a time in an Actor?
- SBT: Watch source and test source changes at the same time
- Why is Deferred factory method has return value in the context of F
- Why do implicits which are defined in a separate trait after the usage result in a compile error?
More Query from same tag
- Spack [Scala]: Reduce a nested tuple value by key
- Scala: How to Unit Test a function I have which makes an API call using mock/stub?
- Time consuming write process of Spark Dataset into the Oracle DB using JDBC driver
- Playframework scala helper for select input with optgroup
- Scala Function.tupled and Function.untupled equivalent for variable arity, or, calling variable arity function with tuple
- Gatling repeat action
- play framework forms without helpers -not getting the errors
- Scala - better way to reformat/grouping List/Map to map
- Akka actors (Scala) How to get heap dump on out of memory
- scala - mock function and replace implementation in tests
- Reading a matrix from a text file as RDD of vectors
- Create ReaderT[F, D, A] from F[A]
- Define a static variable in a function like c++
- UDF is not working to get file name in spark scala
- List to List of Lists in Scala
- How to extract RDD's data to Java ArrayList?
- Cannot load spark json dataframe into a hive table
- Difference between any and parametric polymorphism scala?
- What does this sign "<:" mean in scala?
- How to write less code for a long if-else statement in Scala (code review)
- Error while running UDF on dataframe columns
- Type mismatch with If statement containing bitwise operators
- Can we set String column as partitionColumn?
- Apply functions on each group in Data Frame
- jquery ajax response append to sclect tag (state-district wise)
- Creating a scheduler/timer inside of akka typed actor
- Why do scala maven artifacts have an artifact for each scala version instead of a classifier per scala version?
- Why does this function parameter need double braces on a tuple?
- Multivariate interpolation in Scala
- Connect to SQLite in Apache Spark