这段代码有什么问题?
object Numbers extends App {
def decode(number: Int) : String = number match {
case _ if _ % 15==0 => "fizzbuzz"
case _ if _ % 3==0 => "fizz"
case _ if _ % 5==0 => "buzz"
case _ => _.toString
}
val test = List(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
test.map(decode).foreach(println)
}
我收到以下错误:
error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: String
case _ if _%15==0 => "fizzbuzz"
为什么编译器不知道参数类型?谢谢