trait IsValueClass[A] extends Any
A base trait for a user-defined value-class that standardizes the name of the value-class val to "underlying" and the toString implementation to underlying.toString. This allows creating an implicit conversion from an instance of any value-class to its underlying representation.
For details on value-class see: http://docs.scala-lang.org/overviews/core/value-classes.html
Example:
implicit class Name(underlying: String) extends AnyVal with IsValueType[String]
Note1: When creating a value-class for String, it is necessary to create an implicit view to StringOps to use the Scala extended String methods on instances of the value-class. Example:
object Name { import scala.collection.immutable.StringOps implicit def stringOps_Name(n: Name) = new StringOps(n.underlying) }
Note2: while almost every method on underlying can be used on the value-class without special code, the equals method is a special case that still requires wrapping the right-hand type in the value-class to match the other side. Ex:
Name("Hal") == "Hal" // always returns false + compiler warning Name("Hal") == Name("Hal") // works correctly
- A
type of underlying value class (Note: this parameter does not require inheritance from AnyVal since this would prevent using the trait with java.lang.String which does not inherit AnyVal)
- Alphabetic
- By Inheritance
- IsValueClass
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
equals(arg0: Any): Boolean
- Definition Classes
- Any
-
def
hashCode(): Int
- Definition Classes
- Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
toString(): String
- Definition Classes
- IsValueClass → Any