shorthand for this.tpe.<:<
shorthand for this.tpe.<:<
shorthand for this.tpe.=:=
shorthand for this.tpe.=:=
if B
is a lower bound to type A
, then return this
cast to
TypeKey[_ >: B]
, wrapped in an option.
if B
is a lower bound to type A
, then return this
cast to
TypeKey[_ >: B]
, wrapped in an option. this method is provided for Scala
grammer only, so that you can reuse this type to safely please the compiler
into matching types. however, the return value will remain ==
to this
,
so it can be reused as a key into a TypeKeyMap
. but it will probably not
be equal to a TypeKey[_ >: B]
generated by other means. in short, the
results of this method are for short term use, as keys with the desired type.
Here's an example how this works:
val tki = typeKey[Int] val tkli = typeKey[List[Int]] val tkla = typeKey[List[_]] val tksi = typeKey[Set[Int]] val keys: List[TypeKey[_]] = List(tki, tkli, tkla, tksi) // this is how i type: val lotks: List[Option[TypeKey[_ >: String]]] = keys.map(_.castToLowerBound[String]) val lotki: List[Option[TypeKey[_ >: Int]]] = keys.map(_.castToLowerBound[Int]) val lotkli: List[Option[TypeKey[_ >: List[Int]]]] = keys.map(_.castToLowerBound[List[Int]]) val lotkla: List[Option[TypeKey[_ >: List[_]]]] = keys.map(_.castToLowerBound[List[_]]) // this is how i equal: keys.map(_.castToLowerBound[String]) should equal (List(None, None, None, None)) keys.map(_.castToLowerBound[Int]) should equal (List(Some(tki), None, None, None)) keys.map(_.castToLowerBound[List[Int]]) should equal (List(None, Some(tkli), Some(tkla), None)) keys.map(_.castToLowerBound[List[_]]) should equal (List(None, None, Some(tkla), None))
if B
is an upper bound to type A
, then return this
cast to TypeKey[_ <: B]
, wrapped in an option.
if B
is an upper bound to type A
, then return this
cast to TypeKey[_ <: B]
, wrapped in an option.
this method is provided for Scala grammer only, so that you can reuse this type to safely please the
compiler into matching types. however, the return value will remain ==
to this
, so it can be reused as
a key into a TypeKeyMap
. but it will probably not be equal to a TypeKey[_ <: B]
generated by other
means. in short, the results of this method are for short term use, as keys with the desired type.
Here's an example how this works:
val tki = typeKey[Int] val tkli = typeKey[List[Int]] val tkla = typeKey[List[_]] val tksi = typeKey[Set[Int]] val keys: List[TypeKey[_]] = List(tki, tkli, tkla, tksi) // this is how i type: val lotks: List[Option[TypeKey[_ <: String]]] = keys.map(_.castToUpperBound[String]) val lotki: List[Option[TypeKey[_ <: Int]]] = keys.map(_.castToUpperBound[Int]) val lotkli: List[Option[TypeKey[_ <: List[Int]]]] = keys.map(_.castToUpperBound[List[Int]]) val lotkla: List[Option[TypeKey[_ <: List[_]]]] = keys.map(_.castToUpperBound[List[_]]) // this is how i equal: keys.map(_.castToUpperBound[String]) should equal (List(None, None, None, None)) keys.map(_.castToUpperBound[Int]) should equal (List(Some(tki), None, None, None)) keys.map(_.castToUpperBound[List[Int]]) should equal (List(None, Some(tkli), None, None)) keys.map(_.castToUpperBound[List[_]]) should equal (List(None, Some(tkli), Some(tkla), None))
the full type name for the type represented by this key
a copy of this TypeKey
, but with the underlying TypeTag
replaced with a copy that has a different mirror.
a copy of this TypeKey
, but with the underlying TypeTag
replaced with a copy that has a different mirror.
this method is helpful for managing code that crosses ClassLoader boundaries.
the simple type name for the type represented by this key
the scala-reflect TypeTag
for type A
the scala-reflect Type
for type A
a list of type keys for the type arguments of this type
behaves much like a
scala.reflect.runtime.universe.TypeTag
, except that it can also be safely used as a key in a hash or a set. Two type keys will be equal if and only if their underlying types are equivalent according to method=:=
inscala.reflect.api.Types.Type
. The hashCode method does its best to produce unique hash values, and always produces values compatible with equals.type keys are provided by an implicit method in package typekey, so you can get one implicitly like so:
or you can get one explicitly like so:
or if you already have a
TypeTag
at hand:the type that we are keying one
the scala-reflect
TypeTag
for typeA