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);
}
初始化:
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);
}
初始化:
AnInterface impl = (inst, num) -> {
//...
}
如果AnInterface
是Java,您可以使用SAM conversion:
val impl = AnInterface { inst, num ->
//...
}
否则,如果接口是Kotlin...
interface AnInterface {
fun doSmth(inst: MyClass, num: Int)
}
...you can use the object
syntax for implementing it anonymously:
val impl = object : AnInterface {
override fun doSmth(inst:, num: Int) {
//...
}
}