Lambdas and variance


#1

Well, simple question: why this code does not compile ??

open class A
class B: A()

fun main(args: Array<String>) {   
  var f: (A) -> Boolean = { arg: B -> false }
}
?
what’s problem if I pass B() to “(A) -> Boolean” function ?


#2

If this code compiled, I could create a `class C: A` and pass it to your lambda, which would then try to cast it to a `B` and crash.


#3

Oh. Thanks.