In Scala, I would like to do:
class Identifier(val str: String) { override def toString(): String = str } class Variable(t: Type, name: Identifier, mutable: Boolean) { override def toString(): String = name }
But I cannot, because Scala will not imply converting name in Variable#toString() to String. Is there a way this can be achieved?
To be clear: I do not want to define an additional method, for example:
object Identifier { implicit def idToString(x: Identifier): String = x.str }
I would like the toString() method to be called for conversion.
source share