简体   繁体   English

Kotlin内部可见性修改器的范围

[英]Scope of internal visibility modifier in Kotlin

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). 即使我创建了一个jar,我也可以从jar外部访问jar中的内部函数(来自与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? 什么是kotlin的模块?

  2. how does the access modifier internal differs from the public modiefier? 访问修饰符内部与公共modiefier有何不同?

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 . Kotlin编译器版本M8(0.8.11)忽略了模块,更确切地说,它的工作就好像所有代码都放在同一个模块中一样,这就是为什么你不能获得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. 从下一个里程碑版本开始,您创建的每个IDE模块都有自己的可见范围,当您尝试从另一个模块访问internal声明时,会出现错误。 Publics, on the other hand, are visible across the whole project. 另一方面,公众在整个项目中都可见。

UPDATE : This has not been turned on in M8, postponed for later 更新 :这在M8中没有打开,推迟了以后

UPDATE : This has been turned on since later Kotlin milestones and betas 更新 :自从后来的Kotlin里程碑和测试版以来,这已经开启

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM