How to override method when instantiating object in Kotlin?

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.

Leave a Comment