https://kotlinlang.org logo
#announcements
Title
# announcements
v

ValV

07/11/2019, 8:37 AM
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

Pavlo Liapota

07/11/2019, 8:40 AM
You can write
Copy code
val c = Completer { arg1, arg2, arg3 -> ... }
👍 1
v

ValV

07/11/2019, 9:05 AM
Thanks 👍 Too many things that I do not know yet...
2 Views