이 일을하는 더 이상하지 않은 방법이 있다는 것을 알고 있지만 왜이 코드가 작동하지 않습니까? (대체로, x += 2
의 첫 번째 시도는 왜 효과가 없습니까?) 스칼라에 대해 처음으로 아주 이상하게 보입니까? 오류 메시지 일부는 implicit def
마법이 제대로 작동하지 않습니까?왜 + = 목록과 함께 작동하지 않습니까?
scala> var x: List[Int] = List(1)
x: List[Int] = List(1)
scala> x += 2
<console>:7: error: type mismatch;
found : Int(2)
required: String
x += 2
^
scala> x += "2"
<console>:7: error: type mismatch;
found : java.lang.String
required: List[Int]
x += "2"
^
scala> x += List(2)
<console>:7: error: type mismatch;
found : List[Int]
required: String
x += List(2)