lundi 4 novembre 2019

How to override private method

I am extending existing Java class which has some private method. And to achieve what I want, I have to to override this private method.

So I read something about Java reflection, and came out with the following:

class CustomSlider : Slider() {
    init {
        Slider::class.java.getDeclaredMethod("drawTrack", Canvas::class.java, Int::class.java, Int::class.java).isAccessible = true
    }

    override fun drawTrack(canvas: Canvas, width: Int, top: Int) {
    }
}

But on the override line, I'm getting an error that it's not possible.

So how can I do this?





Aucun commentaire:

Enregistrer un commentaire