I have a third party Java library which an object with interface like this:
public interface Handler<C> {
void call(C context) throws Exception;
}
How can I concisely implement it in Kotlin similar to Java anonymous class like this:
Handler<MyContext> handler = new Handler<MyContext> {
@Override
public void call(MyContext context) throws Exception {
System.out.println("Hello world");
}
}
handler.call(myContext) // Prints "Hello world"
See Question&Answers more detail:os