trait
AsAny
extends AnyRef
Value Members
-
def
!=
(arg0: AnyRef): Boolean
-
def
!=
(arg0: Any): Boolean
-
def
##
(): Int
-
def
==
(arg0: AnyRef): Boolean
-
def
==
(arg0: Any): Boolean
-
def
asInstanceOf
[T0]
: T0
-
def
clone
(): AnyRef
-
implicit def
convertToAsAnyWrapper
(o: Any): AsAnyWrapper
-
def
eq
(arg0: AnyRef): Boolean
-
def
equals
(arg0: Any): Boolean
-
def
finalize
(): Unit
-
def
getClass
(): java.lang.Class[_]
-
def
hashCode
(): Int
-
def
isInstanceOf
[T0]
: Boolean
-
def
ne
(arg0: AnyRef): Boolean
-
def
notify
(): Unit
-
def
notifyAll
(): Unit
-
def
synchronized
[T0]
(arg0: ⇒ T0): T0
-
def
toString
(): String
-
def
wait
(): Unit
-
def
wait
(arg0: Long, arg1: Int): Unit
-
def
wait
(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
Trait containing an implicit conversion that adds an
asAny
method to anything, which returns the same object as typeAny
.The purpose of this method is to appease the type checker when necessary. For example, in ScalaTest's matchers DSL the type passed to
contain
must be consistent with the element type of the collection on whichshould
is invoked. So this type checks:But this does not type check:
That is all well and good, but it turns out that this does also not type check, because the element type of the collection (
Any
) is a supertype of the type passed to contain (String
):You can appease the type checker by casting the type of
"2"
toAny
, a cast that will always succeed. UsingasAny
makes this prettier: