case class TypeKey[A](tag: scala.reflect.api.JavaUniverse.TypeTag[A]) extends Product with Serializable
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 =:=
in scala.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:
def foo[A : TypeKey]() = { val key = implicitly[TypeKey[A]] }
or you can get one explicitly like so:
val key = typekey.typeKey[List[String]]
or if you already have a TypeTag
at hand:
val tag: TypeTag[A] = ??? val key = TypeKey(tag)
- A
the type that we are keying one
- tag
the scala-reflect
TypeTag
for typeA
- Alphabetic
- By Inheritance
- TypeKey
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
TypeKey(tag: scala.reflect.api.JavaUniverse.TypeTag[A])
- tag
the scala-reflect
TypeTag
for typeA
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (TypeKey[A], B)
-
def
<:<(that: TypeKey[_]): Boolean
shorthand for
this.tpe.<:<
-
def
<:<(that: scala.reflect.api.JavaUniverse.Type): Boolean
shorthand for
this.tpe.<:<
-
def
=:=(that: TypeKey[_]): Boolean
shorthand for
this.tpe.=:=
-
def
=:=(that: scala.reflect.api.JavaUniverse.Type): Boolean
shorthand for
this.tpe.=:=
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
castToLowerBound[B](implicit arg0: TypeKey[B]): Option[TypeKey[_ >: B]]
if
B
is a lower bound to typeA
, then returnthis
cast toTypeKey[_ >: B]
, wrapped in an option.if
B
is a lower bound to typeA
, then returnthis
cast toTypeKey[_ >: 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==
tothis
, so it can be reused as a key into aTypeKeyMap
. but it will probably not be equal to aTypeKey[_ >: 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))
-
def
castToUpperBound[B](implicit arg0: TypeKey[B]): Option[TypeKey[_ <: B]]
if
B
is an upper bound to typeA
, then returnthis
cast toTypeKey[_ <: B]
, wrapped in an option.if
B
is an upper bound to typeA
, then returnthis
cast toTypeKey[_ <: 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==
tothis
, so it can be reused as a key into aTypeKeyMap
. but it will probably not be equal to aTypeKey[_ <: 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))
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
- def ensuring(cond: (TypeKey[A]) ⇒ Boolean, msg: ⇒ Any): TypeKey[A]
- def ensuring(cond: (TypeKey[A]) ⇒ Boolean): TypeKey[A]
- def ensuring(cond: Boolean, msg: ⇒ Any): TypeKey[A]
- def ensuring(cond: Boolean): TypeKey[A]
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(that: Any): Boolean
- Definition Classes
- TypeKey → Equals → AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def formatted(fmtstr: String): String
-
lazy val
fullname: String
the full type name for the type represented by this key
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- lazy val hashCode: Int
-
def
inMirrorOf(key: TypeKey[_]): TypeKey[A]
a copy of this
TypeKey
, but with the underlyingTypeTag
replaced with a copy that has a different mirror.a copy of this
TypeKey
, but with the underlyingTypeTag
replaced with a copy that has a different mirror.this method is helpful for managing code that crosses ClassLoader boundaries.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- lazy val manifest: Manifest[A]
-
lazy val
name: String
the simple type name for the type represented by this key
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- val tag: scala.reflect.api.JavaUniverse.TypeTag[A]
-
def
toString(): String
- Definition Classes
- TypeKey → AnyRef → Any
-
lazy val
tpe: scala.reflect.api.JavaUniverse.Type
the scala-reflect
Type
for typeA
-
lazy val
typeArgs: List[TypeKey[_]]
a list of type keys for the type arguments of this type
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
- def →[B](y: B): (TypeKey[A], B)