kotlin generics in KFunction1

Viewed 3907

Suppose, you have two classes TestA and TestB. Suppose that TestA extends TestB:

public class TestB {
    private int intProp;
    public int getIntProp() {
        return intProp;
    }
    public void setIntProp(int intProp) {
        this.intProp = intProp;
    }
}


public class TestA extends TestB {
    private String strProp;
    public String getStrProp() {
        return strProp;
    }
    public void setStrProp(String strProp) {
        this.strProp = strProp;
    }
}

Now I create next line of code:

var getter1: KFunction1<TestA, Int> = TestA::getIntProp

As you can see, I access from TestA class method of TestB: TestA::getIntProp SO the result is instance of KFunction1 with generic params < TestA, Int >

Now I try to create next line of code

var getter2: KFunction1<TestA, Int> = TestB::getIntProp

And it also works and compiles, while I expect that there will be compile error

1 Answers
Related