liveBook · Manning

Module

As explained in Kotlin in Action, 2E

A module is a distinct unit of Kotlin compilation whose declarations share an internal visibility boundary.

A module is a set of Kotlin files compiled together, such as a Gradle source set, Maven project, or IntelliJ IDEA module. Kotlin uses the module boundary to enforce internal visibility and encapsulate implementation details. section 4.1.3

Internal declarations inside a module

Marking a class or top-level declaration internal makes it visible throughout its module but unavailable to external modules. A Gradle test source set can access internal declarations from its main source set. Kotlin uses packages for namespaces, not package-private visibility. section 4.1.3

Table 4.2 Kotlin visibility modifiers (view table figure)

Modifier

Class member

Top-level declaration

public (default)

Visible everywhere

Visible everywhere

internal

Visible in a module

Visible in a module

protected

Visible in subclasses

—

private

Visible in a class

Visible in a file

Compare internal visibility with public, protected, and private visibility across class members and top-level declarations. section 4.1.3

How Kotlin in Action, 2E covers it

How deep it goes
Defines modules and internal visibility, then contrasts them with file, class, package, and public boundaries.
Examples
Uses Gradle source sets, Maven projects, IntelliJ IDEA modules, and test access to main-source internal declarations.
What it assumes
Assumes familiarity with Kotlin declarations and contrasts its visibility model with Java conventions.
What you can do after
Operate/configure module boundaries and choose internal visibility for implementation details.
How it connects
Connects modules with internal visibility, public APIs, private visibility, packages, and Java package-private visibility.

Also explained in

Compare how 35 books explain module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kotlin in Action, 2E. The section links point to the parts of the book it draws on.