I am not sure if it is possible to do what you want. The apply method takes a parameter of type [T], but if you do not specify it, the compiler does not know what type T exactly represents. In this case, it does not transmit anything, a subtype of any other type.
Using your code, setting the type parameter gives the following result:
scala> VariantMap[Int]("a")
res0: Option[Int] = Some(1)
scala> VariantMap[String]("a")
res1: Option[String] = Some(1)
, , .
:
object VariantMap {
import scala.reflect.Manifest
private var _map= Map.empty[Any,(Manifest[_], Any)]
def update[T](name: Any, item: T)(implicit m: Manifest[T]) {
_map = _map(name) = (m, item)
}
def apply[T](key:Any)(implicit m : Manifest[T]): Option[T] = {
val o = _map.get(key)
o match {
case Some((om: Manifest[_], s : Any)) => if (om None
}
}
}
scala> VariantMap("a")
res0: Option[Nothing] = None
scala> VariantMap[Int]("a")
res1: Option[Int] = Some(1)
scala> VariantMap[String]("a")
res2: Option[String] = None
, , , ( ), .