---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 15 Edition"
java_version: 15
chapter: "Chapter 5. Loading, Linking, and Initializing"
section: "5.4"
heading: "5.4. Linking"
parent: "Chapter 5. Loading, Linking, and Initializing"
source: https://docs.oracle.com/javase/specs/jvms/se15/html/jvms-5.html#jvms-5.4
id: "5.4"
url: https://jvm.obfuscated.software/jvms/se15/5.4.html
raw: https://jvm.obfuscated.software/jvms/se15/5.4.md
---

# 5.4. Linking

Linking a class or interface involves verifying and preparing that class or interface, its direct superclass, its direct superinterfaces, and its element type (if it is an array type), if necessary. Linking also involves resolution of symbolic references in the class or interface, though not necessarily at the same time as the class or interface is verified and prepared.

This specification allows an implementation flexibility as to when linking activities (and, because of recursion, loading) take place, provided that all of the following properties are maintained:

- A class or interface is completely loaded before it is linked.

- A class or interface is completely verified and prepared before it is initialized.

- Errors detected during linkage are thrown at a point in the program where some action is taken by the program that might, directly or indirectly, require linkage to the class or interface involved in the error.

- A symbolic reference to a dynamically-computed constant is not resolved until either (i) an *ldc*, *ldc_w*, or *ldc2_w* instruction that refers to it is executed, or (ii) a bootstrap method that refers to it as a static argument is invoked.

  A symbolic reference to a dynamically-computed call site is not resolved until a bootstrap method that refers to it as a static argument is invoked.

For example, a Java Virtual Machine implementation may choose a "lazy" linkage strategy, where each symbolic reference in a class or interface (other than the symbolic references above) is resolved individually when it is used. Alternatively, an implementation may choose an "eager" linkage strategy, where all symbolic references are resolved at once when the class or interface is being verified. This means that the resolution process may continue, in some implementations, after a class or interface has been initialized. Whichever strategy is followed, any error detected during resolution must be thrown at a point in the program that (directly or indirectly) uses a symbolic reference to the class or interface.

Because linking involves the allocation of new data structures, it may fail with an `OutOfMemoryError`.

**Sections:**

- [5.4.1. Verification](5.4.1.md)
- [5.4.2. Preparation](5.4.2.md)
- [5.4.3. Resolution](5.4.3.md)
- [5.4.4. Access Control](5.4.4.md)
- [5.4.5. Method Overriding](5.4.5.md)
- [5.4.6. Method Selection](5.4.6.md)
