this question has answer here:
why like:
val map = map(....) list(1,2,3,4).contains(map) or
list(1,2,3,4).contains("hello") are allowed compile. though scala type safe.
if consult scaladocs list.contains, notice following method signature:
def contains[a1 >: a](elem: a1): boolean
of particular interest type parameters, [a1 >: a] if break down, get:
a, type of elements list containsa1, type of element searching in list>:, symbol representing lower bound
this should interpreted a1 lower bounded a, a1 either of type or more generic type. see http://www.scala-lang.org/old/node/137 more information lower type bounds.
you have list of int. ask if list contains string. since any >: string , any >: int, compiler doesn't complain. same circumstances apply map scenario.
Comments
Post a Comment