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?

推荐答案

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.

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相关问答推荐

这些Kotlin函数等效吗?

Kotlin协程挂起继续线程

在Webflux应用程序中通过kotlin协程启动fire and forget job

Kotlin Coroutine()是如何工作的?S阻止了.

Kotlin stlib中是否有用于将列表<;对<;A,B&>;转换为对<;列表<;A&>,列表<;B&>;的函数

init中的NPE抽象函数变量

Kotlin 使用委托进行隐式覆盖

为 Gradle 子项目配置 Kotlin 扩展

如何从 kotlin 中的数据类访问 val?

伴随对象在变量更改时更改它的值

Kotlin 有垃圾收集器吗?如果是这样,它基于哪种算法?

AIDL 中的 Parcelize 注释:Incompatible types: Object cannot be converted to MyCustomObject

在 Spring Framework 5.1 中注册具有相同名称的测试 bean

如何通过反射使用 Kotlin 对象

Kotlin 具体化的泛型不会按计划保持类型

取消信号上的kotlin流量采集

什么是开放式property?为什么我不能将其设置器设为private私有?

创建Spring和#180的实例;Kotlin中的参数化类型引用

具有泛型param的Kotlin抽象类和使用类型param的方法

将字符串转换为HashMap的最简单方法