CONSTANT_Class tag 7
A class or interface, by its internal name: dots become slashes.
- Tag
7- Since
- class file 45.0 (Java 1.0)
- Size
- 3 bytes
- Loadable
- yes, with
ldc,ldc_w(class files 49.0 and later) - Referred to by
- this_class, super_class and interfaces
- Fieldref, Methodref and InterfaceMethodref
- new, anewarray, multianewarray, checkcast, instanceof
- catch types in exception tables
- InnerClasses, NestHost, NestMembers, PermittedSubclasses, Exceptions
Layout
| Type | Field | What it holds |
|---|---|---|
u1 | tag | 7 |
u2 | name_index | a Utf8: the internal name, such as java/lang/String, or an array descriptor such as [I |
What it is for
A class or interface, by its internal name: dots become slashes. Array classes use their descriptor instead ([Ljava/lang/String; for String[]).
Since Java 5, ldc of a Class constant pushes the java.lang.Class object: that is what Foo.class compiles to. Before that, javac generated a synthetic class$ method that called Class.forName.
How common it is
JDK 25.0.5's java.base has 84,644 Class constants in 7,391 of its 7,391 classes: 8.0% of all 1,059,609 constants.
A real one, byte by byte
Constant #2 of Hello.class, compiled by javac 25:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 15 | 3 bytes | #2 Class | java/lang/Object |
| 15 | 07 | tag | 7 (Class) |
| 16 | 00 04 | name_index | #4 |
Specification: JVMS §4.4, CONSTANT_Class_info (Java SE 25).