Careeroza
internal and Modules
What is a Module?
A module is a set of Kotlin files compiled together: a Gradle module (e.g. :app, :core:network), a Maven project, or an IntelliJ module. internal code can be used anywhere inside that module but is hidden from other modules.
:core:network module :app module --------------------------- ------------------------ internal class HttpEngine --X--> cannot see HttpEngine public class ApiClient -----> can use ApiClient
Example
// In module :core:network
internal class HttpEngine { // implementation detail
fun execute(url: String): String = "..."
}
class ApiClient { // public API of the module
private val engine = HttpEngine()
fun get(path: String) = engine.execute("https://api.example.com$path")
}Note: internal is ideal for multi-module Android apps and libraries: helpers stay usable across your own module without becoming part of the public API.