trait
      
      
        IsValueClass[A] extends Any
      
      
      
          
        
      
      
        
        
        
        
              Abstract Value Members
              - 
      
      
      
      
        abstract 
        def
      
      
        getClass(): Class[_]
      
      
      
        
      
    
      
     - 
      
      
      
      
        abstract 
        def
      
      
        underlying: A
      
      
      
        
      
    
      
     
             
        
              Concrete Value Members
              - 
      
      
      
      
        final 
        def
      
      
        !=(arg0: Any): Boolean
      
      
      
        
      
    
      
     - 
      
      
      
      
        final 
        def
      
      
        ##(): Int
      
      
      
        
      
    
      
     - 
      
      
      
      
        final 
        def
      
      
        ==(arg0: Any): Boolean
      
      
      
        
      
    
      
     - 
      
      
      
      
        final 
        def
      
      
        asInstanceOf[T0]: T0
      
      
      
        
      
    
      
     - 
      
      
      
      
        
        def
      
      
        equals(arg0: Any): Boolean
      
      
      
        
      
    
      
     - 
      
      
      
      
        
        def
      
      
        hashCode(): Int
      
      
      
        
      
    
      
     - 
      
      
      
      
        final 
        def
      
      
        isInstanceOf[T0]: Boolean
      
      
      
        
      
    
      
     - 
      
      
      
      
        
        def
      
      
        toString(): String
      
      
      
        
      
    
      
     
             
        
        
         
        
        
       
      
      
     
      
A base trait for a user-defined value-class that standardizes the name of the value-class val to "underlying" and toString to underlying toString. This allows creating a 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 value-class: implicit class Name(underlying: String) extends AnyVal with IsValueType[String]
Note1: When using 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 for Name above: 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
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)