I do not want to repeat any of the great arguments for package-private visibility.
However, it is really strange to me that Kotlin 1.4 introduced the Explicit API mode which solves very similar problem that the package visibility would do. Java 9 modules +
package visibiliy, would make the
internal visibility an inferior tool for the JVM.
My main point is to propose a possible solution for us old farts who find package-private visibility a very handy tool in our toolbox.
Introducing this feature to Kotlin will take a long time if it happens at all.
In the meantime, we can build a temporary (permanent?) solution to this issue using existing tools.
With Kotlin 1.4 it should be possible to write a compiler plugin that would change the default visibility of Kotlin classes from
This option should be opt-in and probably on a package by package basis.
To opt-in into this behaviour you would add annotation on the package (in package-info.java?).
The annotation could be something like
Classes and free methods in such packages without explicit visibility modifier would be compiled with package visibility.
This could relatively easily solve the problem without the need to change the language.
Just an idea. Happy to hear comments. Maybe similar tools already exist?