Different types in Map Scala
问题 I need a Map where I put different types of values (Double, String, Int,...) in it, key can be String. Is there a way to do this, so that I get the correct type with map.apply(k) like val map: Map[String, SomeType] = Map() val d: Double = map.apply("double") val str: String = map.apply("string") I already tried it with a generic type class Container[T](element: T) { def get: T = element } val d: Container[Double] = new Container(4.0) val str: Container[String] = new Container("string") val m: