Inheritance from Java class with a public method accepting a protected class in Kotlin

Nikolay Romanov :

I have this situation: There are a Java class

public class A {

    public void overrideMe(B param){
        //TODO: override me in Kotlin!
    }

    protected static class B {

    }
}

and a Kotlin class, which inherits from it and has to override method "overrideMe"

class K: A() {
    override fun overrideMe(param: B) {
        println("Wow!")
    }
}

But Kotlin doesn't allow this behaviour.

'public' function exposes its 'protected (in A)' parameter type B

Is there any way how to resolve this one?

P.S. It's not just a synthetic case - I faced this problem when I tried to implement custom Spring AmqpAppender and to override it's postProcessMessageBeforeSend method.

Nikolay Romanov :

Well, after all, the conclusion is: there is no way to solve this situation in pure Kotlin.

I hope that AmqpAppender.Event will become public in the nearest future.

Even if Java allows that behaviour, having no-public arguments in public methods seems like a bad design for me (also for the developers of Kotlin).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=457931&siteId=1