class Username(underlying: String) extends AnyVal
println(Username("dave"))
class Username(underlying: String) extends AnyVal {
override def toString : String = {underlying.toString}
}
I think what you want are case classes.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I expected the toString method to return 'dave' as the value, however it seems to be printing out the object reference. I had expected the new AnyVal to behave like a String object...
--
AnyRef
AnyRef
Not sure this is what you want to do ...
--
If you want a value class, you must explicitly extend AnyVal. Universal traits can be extended by non-value classes.
Also, toString, iirc, is treated as any other method on a value class. It receives a staticish method that can be called to remove the object ref.
Please check out the value class SIP for details on special casing of hashcode and equals. I think those are the only ones that get special cased....