2021年3月20日星期六

Kotlin recursive problem when type checking

I have the following code which i think is valid, because the recursion happens as a result of a callback. It's not called directly as a result of the function call. But the compiler seems to think there is a recursion issue

class Model(listener: CallBack) {      interface CallBack {          fun onSomething()      }  }    class SomeClass {     private fun createModel() = Model(callBack)               private val callBack = object : Model.CallBack {              override fun onSomething() {              val anotherModel = createModel()          }     }  }  
Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly  

Is there a workaround for this?

https://stackoverflow.com/questions/66728183/kotlin-recursive-problem-when-type-checking March 21, 2021 at 10:00AM

没有评论:

发表评论