Kotlin has no way to resolve this , and here's why:
The difference is that protected actually means something very subtle in Kotlin than in Java.
protected in Kotlin means:
kotlin protected: the same as private (visible inside the file containing the declaration) +, also visible in subclasses;
protected in Java means:
protected java : access to an element can only be accessed in its own package (as well as in the private package) and, in addition, by subclassing its class in another package.
And with this knowledge, the problem should be clear, protected static class B in Kotlin is more like private static class B in Java. Therefore, the warning is correct.
The Kotlin-Java Interop manual states the following:
protected remains protected (note that Java allows access to protected members from other classes in one package, and Kotlin does not, so Java classes will have wider access to the code );
Output:
This means that Kotlin interprets Java-protected as if it were Kotlin- protected ergo, there is no way to implement class K in Kotlin as it is. The least you need to do to get it working is to create C extends A (in Java) that handles all of B public access and then extends this class in Kotlin. As in this release, Calling Protected Static Methods
Criminal:
The main problem is the behavior of Javas static nested classes , which
interacts with instance members of its outer class (and other classes), like any other top-level class. In essence, a static nested class is behaviorally a top-level class that was nested in another top-level class for ease of packaging .
This convenient behavior creates the problem first.
Side note:
Probably the best match for Java- protected is Kotlins internal , which provides the best level of encapsulation.
kotlin internal: any client inside this module that sees the declaration class sees its internal members,