As promised at http://docs.scala-lang.org/overviews/core/value-classes.html, this works:
class Wrapper(val self: Int) extends AnyVal {
def toHexString: String = java.lang.Integer.toHexString(self)
}
println(12.toHexString)
But this doesn't compile:
class Wrapper(val self: Int) extends AnyVal {
def whyNot: String = java.lang.Integer.toHexString(self)
}
println(12.whyNot)
Why not? The only thing I changed is the name of the method!
Here is the error message:
error: value whyNot is not a member of Int
println(12.whyNot)
^
Yes, I have double-checked for schtupit Unicode characters inside whyNot
.