scottazord
scottazord

Reputation: 178

Kotlin + MVP - accidental override

I'm using Kotlin & MVP together and stumbled on a little annoyance.

I'm getting an "accidental override" error (as you can tell from below). Are there any resolutions to this, besides changing either the member variable name or the getX() in the MainView interface.

From what i researched, there isn't a way to prevent kotlin from generating the getter for 'x'.

class MainActivity : Activity(), MainView {
    val x: String // Accidental override

    override fun getX(): String {
        return x
    }
}

interface MainView {
    fun getX(): String
}

Upvotes: 2

Views: 205

Answers (1)

zsmb13
zsmb13

Reputation: 89578

You can make your property private to prevent a getter being generated for it:

private val x: String = ""

Alternatively, you can make it a simple Java field instead of a property with the @JvmField annotation:

@JvmField val x: String = ""

Upvotes: 5

Related Questions