Class-File API (2nd preview)
A supported way to read and write bytecode, replacing everyone's bundled copy of ASM.
Open this lesson in the learning hubKey points
- Frameworks generate and rewrite bytecode constantly - proxies, mocks, instrumentation.
- They all shade a copy of ASM, which must be updated for every new class-file version.
- JEP 466 gives the JDK its own API that always understands the class file format it ships with.
- It is immutable and tree-shaped: parse a
ClassModel, transform it, write new bytes. - You will rarely call it directly, but it is why your framework upgrades should get less painful.
The Class-File API exists so tool authors stop shipping a bytecode library that lags every JDK release.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Java 23 Course course, and every lesson in it is listed on the Java 23 Course contents page.