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. AsAny
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
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. final def !=(arg0: AnyRef): Boolean

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

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

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

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

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

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.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.

  9. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

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

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

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

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

    Definition Classes
    AnyRef
  19. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any

Ungrouped