Does the scala compiler do anything to optimize implicit classes? -


say have implicit class like:

implicit class richstring(str: string) {   def sayhello(): string = s"hello, ${str}!" } 

we can use method sayhello if defined on string class

"world".sayhello 

does scala compiler optimize static call avoid overhead of constructing richstring object?

scala compiler optimises method call if specify class extends anyval. these called value classes.

example docs, link given below:

class richint(val self: int) extends anyval {   def tohexstring: string = java.lang.integer.tohexstring(self) } 

http://docs.scala-lang.org/overviews/core/value-classes.html


Popular posts from this blog