In val int_string = "Int"
the string "Int"
is a runtime thing.
In val m: Map[Int,Double] = ???
the type Int
is a compile-time thing.
Runtime vs. Compile time
You can't have Int
at compile time (i.e. earlier) based on information at runtime (i.e. later).
You should provide more details how you're going to use Map[Int,Double]
, why is Map[Any,Double]
not enough etc.
Depending on your use case, Map[Any,Double]
(or even Map[Any,Any]
) could be enough or something else can be done or in rare cases, when Int
is actually significant, one can use reflective toolbox (creating new compile time inside runtime)
tb.eval(tb.parse(s"val m: Map[$int_string,Double] = ???"))
Scala - looping over case class names to use as type parameters
Covariant case class mapping to its base class without a type parameter and back
Invoke a template Scala function with a type stored as wild card classTag?
test for membership in Scala type class (2)
Scala resolving Class/Type at runtime + type class constraint
scala get generic type by class