Monica
Monica

Reputation: 436

How to ovveride java method in Kotlin class

I have abstract java class. Also I have kotlin class which extends abstract java class. Why the overrides java methods doesn't calls in kotlin class? For example:

public abstract class A {
    public void myMethod() {
   Log.d("test", "test");
    }
}


open class B:A(){
   override fun myMethod {
        super.myMethod()    // doesn't called
    }
}

Upvotes: 1

Views: 64

Answers (1)

Pavel Erokhin
Pavel Erokhin

Reputation: 56

Probably you just doesn't call myMethod from class B.

public abstract class A {
    public void myMethod() {
        System.out.println("test");
    }
}
open class B : A() {
    override fun myMethod() {
        super.myMethod()
    }
}

fun main() {
    B().myMethod()
}

Code above will print test in the console.

Upvotes: 1

Related Questions