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

TypeFieldWhat it holds
u1tag7
u2name_indexa 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:

OffsetBytesFieldValue
153 bytes#2 Classjava/lang/Object
1507tag7 (Class)
1600 04name_index#4

Open in the viewer

Specification: JVMS §4.4, CONSTANT_Class_info (Java SE 25).