Module java.base
Package java.lang.classfile

# Interface ClassFileBuilder

≠
public abstract sealed interface ClassFileBuilder<E, B>
extends java.util.function.Consumer<E>
permits java.lang.classfile.ClassBuilder, java.lang.classfile.CodeBuilder, java.lang.classfile.FieldBuilder, java.lang.classfile.MethodBuilder
Comparing master and cf

Type Parameters:
  `E` - the member element type
  `B` - the self type of this builder type

All Superinterfaces:
  `Consumer<E>`

All Known Subinterfaces:
  `ClassBuilder, CodeBuilder, CodeBuilder.BlockCodeBuilder, FieldBuilder, MethodBuilder`

public sealed interface ClassFileBuilder<E extends ClassFileElement, B extends ClassFileBuilder<E, B>> extends Consumer<E> permits ClassBuilder, FieldBuilder, MethodBuilder, CodeBuilder
A builder for a classfile or portion of a classfile `CompoundElement` , which accepts the member elements to be integrated into the built structure. Builders are rarely created directly; they are passed to handlers by methods such as usually passed as an argument to `Consumer` handlers, such as in `ClassFile.build(ClassDesc, Consumer)` . The handlers should deliver elements to a builder similar to how a `CompoundElement` traverses its member elements.

The basic way a builder accepts elements is through `with(E)` , which supports call chaining. Concrete subtypes of builders usually define extra methods to define elements directly to the builder, such as `ClassBuilder.withFlags(int)` Moved to a paragraph.or

to transforms. Elements of the newly built entity can be specified abstractly (by passing a `ClassFileElement` to `with(ClassFileElement)` or concretely by calling the various `withXxx` methods.

`CodeBuilder.aload(int)` .

Whether a member element can appear multiple times in a compound structure affects the behavior of the element in `ClassFileBuilder` s. If an element can appear at most once but multiple instances are supplied to a `ClassFileBuilder` , the last supplied instance appears on the built structure. If an element appears exactly once but no instance is supplied, an unspecified default value element may be used in that structure.

Due to restrictions of the `class` file format, certain member elements that can be modeled by the API cannot be represented in the built structure under specific circumstances. Passing such elements to the builder causes `IllegalArgumentException` . Some `ClassFile.Option` s control whether such elements should be altered or dropped to produce valid `class` files.Moved to a paragraph.

Sealed Class Hierarchy Graph:
Since:
  24
See Also:
  - `CompoundElement`
  - `ClassFileTransform`

## Methods

- ≠
  public default void accept(E arg0)
  Comparing master and cf

  ### accept

  default void accept (E e)
  Integrate Integrates the `ClassFileElement` member element into the entity structure being built.
  Specified by:
    `accept` in interface `Consumer<E extends ClassFileElement>`
  API Note:
    This method exists to implement `Consumer` ; users can use `with(E)` for call chaining.
  Parameters:
    `e` - the member element
  Throws:
    `IllegalArgumentException` - if the member element cannot be represented in the `class` file format
- =
  public abstract java.lang.classfile.constantpool.ConstantPoolBuilder constantPool()
- ≠
  public default B transform(java.lang.classfile.CompoundElement<E> arg0, java.lang.classfile.ClassFileTransform<?, E, B> arg1)
  Comparing master and cf

  ### transform

  default B transform (CompoundElement<E> model, ClassFileTransform<?, E, B> transform)
  Apply Applies a transform to a modelcompound structure, directing results to this builder.

  Moved to a paragraph.The transform will receive each element of the compound structure, as well as this builder for building the structure. The transform is free to preserve, remove, or replace elements as it sees fit.

  A builder can run multiple transforms against different compound structures, integrating member elements of different origins.

  API Note:
    Many subinterfaces have methods like `ClassBuilder.transformMethod(MethodModel, MethodTransform)` or `MethodBuilder.transformCode(CodeModel, CodeTransform)` . However, calling them is fundamentally different from calling this method: those methods call the `transform` on the child builders instead of on itself. For example, `classBuilder.transformMethod` calls `methodBuilder.transform` with a new method builder instead of calling `classBuilder.transform` on itself.
  Parameters:
    `model` - the model structure to transform
    `transform` - the transform to apply
  Returns:
    this builder
  See Also:
    Moved to a definition list with class notes.Moved to a definition.Moved to an unordered list with class tag-list.
    - `ClassFileTransform`
- ≠
  public abstract B with(E arg0)
  Comparing master and cf

  ### with

  B with (E e)
  Integrate Integrates the `ClassFileElement` member element into the entity structure being built.
  Parameters:
    `e` - the member element
  Returns:
    this builder
  Throws:
    `IllegalArgumentException` - if the member element cannot be represented in the `class` file format

## Summary

Differences
| Elements | Comments | Descriptions | Total
Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed
--- | --- | --- | --- | --- | --- | --- | --- | ---
ClassFileBuilder |  |  |  |  |  |  | 14 | 3 | 7 | 24
accept(E) |  |  |  |  |  |  | 8 | 3 | 1 | 12
transform(CompoundElement,ClassFileTransform) |  |  |  |  |  |  | 4 | 3 |  | 7
with(E) |  |  |  |  |  |  | 5 | 3 | 1 | 9
Total |  |  |  |  |  |  | 31 | 12 | 9 | 52