Kotlin的“内部" Android中的可见性修改器 [英] Kotlin "internal" visibility modifier in Android

查看:53
本文介绍了Kotlin的“内部" 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屋!

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