What would be the equivalent of that code in kotlin, nothing seems to work of what I try:
public interface AnInterface {
void doSmth(MyClass inst, int num);
}
init:
AnInterface impl = (inst, num) -> {
//...
}
What would be the equivalent of that code in kotlin, nothing seems to work of what I try:
public interface AnInterface {
void doSmth(MyClass inst, int num);
}
init:
AnInterface impl = (inst, num) -> {
//...
}
If
AnInterface
is Java, you can work with SAM conversion:Otherwise, if the interface is Kotlin...
...you can use the
object
syntax for implementing it anonymously:You can use an object expression
So it would look something like this:
If you're rewriting both the interface and its implementations to Kotlin, then you should just delete the interface and use a functional type: