Internal keyword advantages

Does anybody knows any advantages (except “code style”) on internal visibility modifier?

Does kotlin drops java interop for these classes/functions (e.g. kotlin can provide full generic API, like in C#, because there is guarantee, that there are no java callers)

Does kotlin add any optimisations, like addition inlining on class unwrapping?

No. Internal methods are callable from Java, and Kotlin does not perform any additional optimizations on them.

I think that internal is important event without any optimizations. The problem it solves is kotlin global functions and global variables. Of course it is useful to be able to call functions without a namespace or class identifier, but on the other hand, in large projects the number of these functions could amount to hundreds if not thousands. In this case it makes sense to close some functions from being seen in outside scope.

1 Like