Can someone explain such thing: in Java code there...
# announcements
v
Can someone explain such thing: in Java code there is an interface
Completer
that has only one method (function)
public abstract int complete(arg1, arg2, arg3)
, so when a variable
completer: Completer?
is assigned, it's done via Java lambda
Copy code
completer = (arg1, arg2, arg3) -> { ... }
Instead of creating (at least) anonymous object of type
Completer
and
override
-ing the
complete
method. Is it possible to do something like that in Kotlin, or I have to do
Copy code
object: Completer {
  override fun complete(arg1, arg2, arg3) { ... }
}
Why I can't do it with lambda -- because the compiler complains that
completer
must be of type
Completer?
, not
(???, ???, ???) -> Unit
p
You can write
Copy code
val c = Completer { arg1, arg2, arg3 -> ... }
👍 1
v
Thanks 👍 Too many things that I do not know yet...