0

As the title describes, the code followed compiles successfully:

val list = List(1, 2, 3, 4)
list.foreach(println(_))

But if I replace the second line with

list.foreach(println(_ + "test"))

compilation shows error with

 missing parameter type for expanded function ((x$2) => x$2.$plus("ss"))
    list.foreach(println(_ + "ss"))

Again I replace the second with

list.foreach(number => println(number + "test"))

it works successfully again. I don't know why it happens. I guess maybe the _'s usage is wrong.

qitian
  • 43
  • 6

0 Answers0