I have a method which calls an object methods that wants a callback object as parameter. The callback object has to have 2 methods defined, onEvent1() and onEvent2().
One way is to do everything inline, but the result is that it's super-nested and becomes unreadable
myObj.method1(object : baseType {
override fun onEvent1() {
10 lines of nested code
}
override fun onEvent2() {
more nested code
}
)
I found it very unreadable given that a method is more 10 lines.
What is the best way to do this in Kotlin?
The only non-kotlin idiomatic way I know is to declare a class and pass an object of it, maybe inner class.
void mymethod() {
class Obj : baseType {
override fun onEvent1() {....}
override fun onEvent2() {....}
}
val obj : Obj
myObj.method1(obj)
}
Is there a better way?