score:-1

Accepted answer

you are talking about value classes I suppose. have a look at the documentation, is fairly simple and understandable: http://docs.scala-lang.org/overviews/core/value-classes.html

Let us know if you have any doubt anyway :)

Edit: trying to simplify the explanation provided on docs

value classes are replaced in compile time. if you have a

case class Name(value: String) extends AnyVal

at compile time, every instance of Name will be replaced by the String representation (I can't tell you in which phase, but I'm also curious now. I will try to find out and add the information here). Another question with some information may be this one I did a couple of weeks ago:

why scala value class#toString contains case class info?, which contains an answer linking to another article

Example:

if you have the following code:

def myFunction(name: Name) = {
  "My name is: " + name.value
}

and you call it

myFunction(Name("Jonh"))

you can imagine it (imagine it, because I'm not sure if this is how it does or if it uses static objects and so on) being replaced by something like

def myFunction(name: String) = {
  "My name is: " + name
}

myFunction("Jonh")

Related Query

More Query from same tag