As you already said, the closest match is currently the package-private modifier. You can apply it by not using any of the other access modifier keywords private
, protected
and public
.
Jigsaw is planned to be integrated into Java 9. It adds native support for modularization to Java. This will allow you to hide packages from other modules: Other modules cannot see anything from the hidden packages, not even the public classes. Thus, a mechanism which is similar to the internal
access modifier of C# will be introduced into Java 9 with the module system. However, there will not be a new access modifier for it.
For now, your best bet it to use OSGi. It enables you to modularize your Java code by applying some class loader magic (The magic is done by OSGi, you do not need to do it by yourself). It is not part of the standard JRE, but it is an separate framework. In OSGi, a module is called a bundle. A bundle has an external interface, defined by a set of exported packages. Other bundles can only use classes from the exported packages. However, the bundle itself can use code which is placed in any of its packages. This allows you to hide classes from other bundles, just like the internal
keyword.
Please keep in mind that it is not an easy decision to use OSGi. It can be quite complex to use and setup. Also, it might not be a good match for application servers, which also tend to do some class loader magic.