A class can only extend from one class or trait, any subsequent extension should use the keyword with
:
Traits are polymorphic.
Traits are polymorphic. Any type can be referred to by another type if related by extension:
Similar to *interfaces* in Java, traits are used to define object types by specifying the signature of the supported methods.
Similar to *interfaces* in Java, traits are used to define object types by specifying the signature of the supported methods. Unlike Java, Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods. In contrast to classes, traits may not have constructor parameters.
Here is an example:
trait Similarity { def isSimilar(x: Any): Boolean def isNotSimilar(x: Any): Boolean = !isSimilar(x) }
This trait consists of two methods isSimilar
and isNotSimilar
. While isSimilar
does not provide a concrete method implementation (it is abstract in the terminology of Java), method isNotSimilar
defines a concrete implementation. Consequently, classes that integrate this trait only have to provide a concrete implementation for isSimilar
. The behavior for isNotSimilar
gets inherited directly from the trait.
A class uses the extends
keyword to mixin a trait if it is the only relationship the class inherits:
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
Please use 'an [Exception] should be thrownBy { ... }' syntax instead
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.