> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Internal Property

An `internal` property in Kotlin is a class member or top-level property whose visibility is strictly scoped to the module in which it is declared. Any code residing within the same compiled module can access the property, while code outside the module cannot resolve the reference.

In Kotlin's compilation model, a "module" is defined as a set of Kotlin files compiled together. This specifically includes:

* An IntelliJ IDEA module.
* A Maven project.
* A Gradle source set (note that `main` and `test` are considered separate source sets, but Kotlin provides special compiler flags to allow tests to access `internal` members of `main`).
* A set of files compiled with a single invocation of the `<kotlinc>` Ant task.

## Syntax

The `internal` modifier is placed before the `val` or `var` keyword. It can be applied at the file level or within a class/object declaration.

```kotlin theme={"dark"}
// Top-level internal property
internal val defaultTimeout: Int = 5000

class ConnectionPool {
    // Class-level internal property
    internal var activeConnections: Int = 0
    
    // Internal property with a restricted setter
    internal var isRunning: Boolean = false
        private set 
}
```

## Access Rules and Inheritance

* **Getters and Setters:** By default, the getter and setter of an `internal` property inherit the `internal` visibility. You can restrict the setter further (e.g., to `private`), but you cannot make it more permissive than the property itself.
* **Overriding:** If an `internal` property is declared in an `open` class, any subclass overriding that property must maintain at least `internal` visibility. It cannot be restricted to `protected` or `private` in the subclass. If no visibility modifier is provided on the override, it implicitly inherits the `internal` visibility.
* **Constructors:** If a property is declared directly in a primary constructor using `internal val` or `internal var`, the property is internal, regardless of the visibility of the class itself.

```kotlin theme={"dark"}
open class Base {
    internal open val identifier: String = "base_id"
}

class Derived : Base() {
    // Valid: Overriding implicitly maintains internal visibility
    override val identifier: String = "derived_id"
    
    // Valid: Overriding explicitly expands visibility to public
    // public override val identifier: String = "public_derived_id"
}
```

## JVM Compilation and Name Mangling

Because the Java Virtual Machine (JVM) lacks a native visibility modifier equivalent to Kotlin's module-level scope (Java's default visibility is package-private, which is fundamentally different), the Kotlin compiler implements `internal` visibility using a workaround in the bytecode.

When compiled to the JVM, the backing field of an `internal` property is generated as `private` by default, exactly like standard Kotlin properties. However, the generated getter and setter methods are made `public`. To enforce the module restriction and prevent external Java code from inadvertently accessing these members, the Kotlin compiler applies **name mangling**.

The compiler appends the module name to the generated `public` getter and setter methods. For example, an internal property named `config` in a module named `core` will result in a generated getter method resembling `getConfig$core()`.

While this prevents accidental access from external Java code, it does not provide cryptographic security; the mangled methods are technically `public` in the bytecode and can still be invoked via Java reflection or by explicitly calling the mangled name from Java.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
