Closed homer-jay closed 5 years ago
internal
is compilation module visibility, which means it is completely different from package
visibility.
Therefore, Kotlin has the addition of internal
visibility, but does not have package
visibility.
Also internal
gets quirky name in Java.
but does not have
package
visibility
OK, so strictly speaking it does not have Java's package-default visibility mechanism, but it allows for "top-level" members directly inside a package:
package foo
fun bar() { ... }
So I agree it's not the same as in Java, because in Kotlin bar
would be accesible by any class in a different package (as long as you import it). But in some sense it fills that void, because top-level members can be used (without the need to import them) by classes in that same package. I thought Java programmers would probably appreciate reading about it.
The problem isn't that you don't need to import it, it's that you can still import it elsewhere and see it.
The top-level declaration is essentially public. 😉
Ok then. That would be like import static
. Closing.
In the visibility section, it says:
This is actually not true, as explained in the official guide, in the section Visibility modifiers - package.
I was also confused by the explanation about internal. In the wiki it says that internal is not equivalent to package, and it is true, but I'd add that internal is "module" visibility (where modules are IntelliJ modules, Maven projects, gradle source sets, etc).