I'm developing a unit test on Android, using mockito-kotlin.
I was trying to spy on a function so I did the following code to do that, and it works fine.
In this case AndroidStudio pointed out that the cast was unnecessary, but when the cast is removed the type is changed to Foo instead of Foo -> Unit:
private val onClick /*:(Foo) -> Unit*/ = spy({ foo: Foo -> } as (Foo) -> Unit)
private val onClick /*:(Foo) -> Unit*/ = { foo: Foo -> }
private val onClick /*:Foo*/ = spy({ foo: Foo -> })
How is the compiler concluding that the type is Foo, and also how should I write the code to avoid the unnecessary cast warning?