Old scala code isn't working anymore

Once uppon a time I written down a code block of the following:

class Role
case object Manager extends Role
case object Developer extends Role

case class Person(name: String, age: Int, role: Role)
    val alice = new Person("Alice", 33, Developer)
    val bob = new Person("Bob", 33, Manager)
    val charlie= new Person("Charlie", 33, Developer)

for(item <- Map(1 -> alice, 2 -> bob, 3 -> charlie)) {
  item match {
    case (id, p @ Person(_, _, Manager)) => println(p + "is overpaid")
    case (id, p @ Person(_, _, _)) => println(p + "is underpaid")
  }
}

On the finishing 2 case blocks , I get the message:
method any2stringadd in object Predef is deprecated (since 2.13.0): Implicit injection of + is deprecated. Convert to String to call +

How does it work now in the 2.13 version of scala?

It still works, but it is deprecated. Which means it might stop working in a future Scala version.

You can make the warning go away by explicitly converting to a String.

p.toString + "is overpaid"

Or—probably preferable—using string interpolation.

s"$p is overpaid"
2 Likes

thanks a lot! I used wrong phrasing, it actualy works but I cant recall seeing ever this warning.

Yeah, the string interpolation version has been generally preferred for a fairly long time now, but they only recently got around to formally deprecating the + version…

2 Likes