> ## 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 Any

`Any` is the root of the Kotlin class hierarchy. Every non-nullable type in Kotlin implicitly inherits from `Any`, making it the ultimate superclass for all non-nullable objects, including user-defined classes, standard library types, and boxed primitives.

## Type Hierarchy: `Any` vs `Any?`

Because Kotlin enforces null safety at the type-system level, there is a strict distinction between `Any` and its nullable counterpart, `Any?`.

* **`Any`**: The top type for all **non-nullable** types. A variable of type `Any` is guaranteed to hold an instance of an object and can never be `null`.
* **`Any?`**: The absolute top type (universal supertype) in Kotlin. It is the supertype of all types, including `Any` itself, and can hold both object instances and `null` references.

```kotlin theme={"dark"}
val nonNullableRoot: Any = "Kotlin" 
// val invalidRoot: Any = null      // Compilation error: Null can not be a value of a non-null type Any

val absoluteRoot: Any? = null       // Valid
val absoluteRootAlso: Any? = 42     // Valid
```

## API Surface

The `Any` class exposes a minimal API footprint. It defines exactly three `open` methods, establishing the foundational contract for object equality, hashing, and string representation across the language.

```kotlin theme={"dark"}
public open class Any {
    /**
     * Indicates whether some other object is "equal to" this one.
     */
    public open operator fun equals(other: Any?): Boolean

    /**
     * Returns a hash code value for the object.
     */
    public open fun hashCode(): Int

    /**
     * Returns a string representation of the object.
     */
    public open fun toString(): String
}
```

Because these methods are declared as `open`, any Kotlin class can override them to provide custom implementations. The `equals` method is marked with the `operator` modifier, allowing it to be invoked implicitly using the structural equality operator (`==`).

## JVM Mapping and `java.lang.Object`

When compiling for the Java Virtual Machine (JVM), Kotlin maps `Any` directly to `java.lang.Object` at runtime. However, at compile time, Kotlin's `Any` intentionally strips away the concurrency and lifecycle methods present in Java's `Object`.

Methods such as `wait()`, `notify()`, `notifyAll()`, `clone()`, and `finalize()` are not part of the `Any` API. This design choice makes the Kotlin standard library platform-agnostic, allowing it to compile to JavaScript (Kotlin/JS) or native binaries (Kotlin/Native) where JVM threading concepts do not apply.

If access to these JVM-specific methods is strictly required in a Kotlin/JVM project, the `Any` reference must be explicitly cast to `java.lang.Object`. Furthermore, standard JVM concurrency rules apply, meaning monitor methods like `wait()` must be called from within a synchronized block.

```kotlin theme={"dark"}
val obj: Any = Any()

// obj.wait() // Compilation error: Unresolved reference: wait

// Explicit cast and synchronization required to access java.lang.Object monitor methods
synchronized(obj) {
    (obj as java.lang.Object).wait()
}
```

Similarly, Java's `getClass()` method is not available on `Any`. Type introspection in Kotlin is handled via the `::class` syntax, which returns a `KClass` instance, or `::class.java` to obtain the underlying Java `Class` instance.

<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>
