Hi! I have code like this: ``` fun <T> test(...
# announcements
p
Hi! I have code like this:
Copy code
fun <T> test(v: T, lambda: (T) -> Unit ) {
  lambda(v)
}
And at call site i have code :
Copy code
val lambda = {v : Any -> println(v)}
test<SomeObject>(SomeObject(), lambda)
The code below wont compile, cause compiler want to have my val lambda have parameter type exact as declared in function. How should I modify my fun test declaration to allow <in Parameter> in lambda parameter?
r
What is
low bound
?
p
I mean <in Parameter>
for example in java it would be:
Copy code
interface Test {
        <T> void test(T t, Consumer<? super T> consumer);
    }
r
(T) -> R
means a function, which accepts
T
and returns
R
. By this meaning,
T
is always
in
, so basically this is the same as
Function
interface in Java: it accepts one thing and returns one thing. In the example you provided
Consumer
accepts
T
and returns nothing. In Kotlin it would be
(T) -> Unit
, so as you wrote
Not sure if I've answered your question.