org.scalautils

AsAny

trait AsAny extends AnyRef

Trait containing an implicit conversion that adds an asAny method to anything, which returns the same object as type Any.

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 which should is invoked. So this type checks:

Set(1, 2) should contain (2)

But this does not type check:

Set(1, 2) should contain ("2")

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):

Set(1, "2") should contain ("2") // Does not compile

You can appease the type checker by casting the type of "2" to Any, a cast that will always succeed. Using asAny makes this prettier:

Set(1, "2") should contain ("2".asAny)

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. AsAny
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Type Members

  1. class AsAnyWrapper extends AnyRef

    Wrapper class with an asAny method that returns the passed object as type Any.

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  7. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. implicit def convertToAsAnyWrapper (o: Any): AsAnyWrapper

    Implicit conversion that adds an asAny method to an object, which returns the exact same object but as type Any.

    Implicit conversion that adds an asAny method to an object, which returns the exact same object but as type Any.

    Attributes
    implicit
  9. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  10. def equals (arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  12. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef → Any
  13. def hashCode (): Int

    Definition Classes
    AnyRef → Any
  14. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  15. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  16. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  17. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  18. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  19. def toString (): String

    Definition Classes
    AnyRef → Any
  20. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  22. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any