Scope of internal visibility modifier in Kotlin

前提是你 提交于 2019-12-22 02:33:43

问题


I have a problem understanding the internal access modifier. In my examples I could not produce any situation where it behaves different then public. Even if I create a jars I can access the internal functions in the jar from outside the jar (from a different package unrelated to the one used in the jar). In the documentation the term module is used but I could not find out what a module is exactly.

My questions thus are:

  1. what is a module in kotlin?

  2. how does the access modifier internal differs from the public modiefier?


回答1:


The Kotlin compiler version M8 (0.8.11) ignores modules, more precisely, it works as if all your code were put into the same module, this is why you can't get a visibility error for internal.

Starting with the next milestone release, every IDE module you create has its own visibility scope, and when you try to access an internal declaration from one module in another, you get an error. Publics, on the other hand, are visible across the whole project.

UPDATE: This has not been turned on in M8, postponed for later

UPDATE: This has been turned on since later Kotlin milestones and betas



来源:https://stackoverflow.com/questions/25813323/scope-of-internal-visibility-modifier-in-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!