Can anyone explain why the following error occurs (Scala 2.10.3)?
scala> new java.util.ArrayList[Integer]()
res0: java.util.ArrayList[Integer] = []
scala> res0.add(0)
res1: Boolean = true
scala> java.util.Collections.binarySearch(res0, 0)
<console>:9: error: type mismatch;
found : java.util.ArrayList[Integer]
required: java.util.List[_ <: Comparable[_ >: Any]]
java.util.Collections.binarySearch(res0, 0)
^
The following does work:
scala> java.util.Collections.binarySearch[Integer](res0, 0)
res4: Int = 0
It seems odd that the compiler would complain about a particular type until I was more explicit about that incorrect type and then it will accept it.
EDIT:
Also note the if you change the first step to:
scala> new java.util.ArrayList[Int]()
there is also a very similar error.