Grzegorz> Hello, I noticed that the following expressions give
Grzegorz> different results:
Grzegorz> Seq(1,2,3,4,5).lastIndexOf(5,4)
Grzegorz> Seq(1,2,3,4,5).lastIndexOfSlice(Seq(5),4)
Grzegorz> Is that normal? Is it the expected outcome?
I'd say open a ticket.
--
Seth Tisue @ Northwestern University | http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Server VM, Java
1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val list: List[Int] = List.range(1,10)
list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> list.indexOf("test")
res1: Int = -1
I expected a compilation error when calling indexOf with a String
since its parameter is of type A of List[A].
Am I missing something?
--
Fabio Cechinel Veronez
def indexOf [B >: A] (elem: B) : Int
The compiler is inferring Any for B.
Nate
You are missing variance. It's the same reason contains takes an Any.
A covariant collection cannot accept invariant parameters.