Kotlin的“内部" Android中的可见性修改器 [英] Kotlin "internal" visibility modifier in Android
问题描述
假设您正在编写一个Android项目(不是库).所有文件都一起编译,因此...在这种情况下使用internal
可见性修饰符是否有意义?
Suppose you're writing an Android project (not a library). All the files are compiled together so... is there any sense to use an internal
visibility modifier in this case?
推荐答案
您可以在一个Android应用程序中拥有多个相互依赖的Gradle模块,在这种情况下,internal
将可见性限制在给定模块内.例如,如果您有一个单独的data
模块来处理数据库和网络任务,并且您只想从该模块公开几个接口,而不是它们的实现,这可能会很有用.
You can have multiple Gradle modules that depend on each other within a single Android application, in that case, internal
restricts visibility to within a given module. This could be useful if, for example, you have a separate data
module that handles database and network tasks, and you only want to expose a couple interfaces from that module, but not their implementations.
否则,如果您不使用多个模块,并且整个应用程序仅位于默认的app
模块中,则与默认的public
可见性相比,internal
修饰符没有什么区别.
Otherwise, if you're not using multiple modules, and your entire application is just in the default app
module, then the internal
modifier makes no difference in comparison to the default public
visibility.
这篇关于Kotlin的“内部" Android中的可见性修改器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!