How to override method when instantiating object in Kotlin?

后端 未结 1 1706
后悔当初
后悔当初 2021-02-02 08:35

In Java, to override method when instantiating new object we can do this

public ActivityTestRule rule = new ActivityTestRule

        
相关标签:
1条回答
  • 2021-02-02 09:12

    If you want to create anonymous inner class, you should use object.

    var rule = object : ActivityTestRule<MainActivity>(MainActivity::class.java) {
        override fun beforeActivityLaunched() {
            super.beforeActivityLaunched()
        }
    }
    

    See also Object Expressions and Declarations.

    0 讨论(0)
提交回复
热议问题