内部可见性修改器在Kotlin中的范围 [英] Scope of internal visibility modifier in Kotlin

查看:55
本文介绍了内部可见性修改器在Kotlin中的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解内部访问修饰符时遇到问题.在我的示例中,我无法表现出任何行为都不同于公众的情况.即使创建了一个jar,我也可以从jar外部(从与jar中使用的软件包无关的其他程序包)访问jar中的内部函数.在文档中使用了模块"一词,但我无法确切地知道什么是模块.

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.

因此,我的问题是:

  1. kotlin中的模块是什么?

  1. what is a module in kotlin?

访问修饰符内部与公共修饰符有何不同?

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

推荐答案

Kotlin编译器M8(0.8.11)会忽略模块,更确切地说,它的工作方式就像将所有代码都放在同一个模块中一样,这就是为什么您不会看到internal的可见性错误.

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.

从下一个里程碑版本开始,您创建的每个IDE模块都有其自己的可见性范围,并且当您尝试从另一个模块中的一个模块访问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.

更新:该功能尚未在M8中启用,已推迟到以后

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

更新:自后来的Kotlin里程碑和Beta版以来,该功能已启用

这篇关于内部可见性修改器在Kotlin中的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆