Module java.base
Package java.lang.classfile

# Interface ClassBuilder

≠
public abstract sealed interface ClassBuilder
extends java.lang.classfile.ClassFileBuilder<java.lang.classfile.ClassElement, java.lang.classfile.ClassBuilder>
permits jdk.internal.classfile.impl.ChainedClassBuilder, jdk.internal.classfile.impl.DirectClassBuilder
Comparing master and cf

All Superinterfaces:
  `ClassFileBuilder<ClassElement, ClassBuilder>, Consumer<ClassElement>`

public sealed interface ClassBuilder extends ClassFileBuilder<ClassElement, ClassBuilder>
A builder for classfiles. Builders are not created directly; they are passed to handlers by methods such as a `class` file. `ClassFile` provides different `build` methods that accept handlers to configure such a builder; `ClassFile.build(ClassDesc, Consumer)` or to class transforms. The elements of a classfile can be specified abstractly (by passing a `ClassElement` to `ClassFileBuilder.with(ClassFileElement)` ) or concretely by calling the various `withXxx` methods suffices for basic usage, while `ClassFile.build(ClassEntry, ConstantPoolBuilder, Consumer)` allows fine-grained control over the constant pool.

Refer to `ClassFileBuilder` for general guidance and caution around the use of builders for structures in the `class` file formatMoved to a paragraph..

Since:
  24
See Also:
  Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.
  - `ClassFile.build(ClassEntry, ConstantPoolBuilder, Consumer)`
  - `ClassModel`
  - `Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.ClassTransform` Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.
Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.

Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.
Moved out of an unordered list with class tag-list.Moved to an unordered list with class tag-list-long.

## Methods

- ≠
  public abstract java.lang.classfile.ClassBuilder transformField(java.lang.classfile.FieldModel arg0, java.lang.classfile.FieldTransform arg1)
  Comparing master and cf

  ### transformField

  ClassBuilder transformField (FieldModel field, FieldTransform transform)
  Adds a field by transforming a field from another class.

  Moved to a paragraph.

  Implementation Note:

  Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block. Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.This method behaves as if:

  Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.Moved to a link with destination #withField(java.lang.classfile.constantpool.Utf8Entry,java.lang.classfile.constantpool.Utf8Entry,java.util.function.Consumer).Moved to a computer code block.withField
      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.(field.fieldName(), field.fieldType(),
                fbMoved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

  b

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.->

  b

      fbMoved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block..

  transformField

      transform
      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.(field, transform))

  ;

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

  Parameters:
    `field` - the field to be transformed
    `transform` - the transform to apply to the field
  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.
    - `FieldTransform`
- ≠
  public abstract java.lang.classfile.ClassBuilder transformMethod(java.lang.classfile.MethodModel arg0, java.lang.classfile.MethodTransform arg1)
  Comparing master and cf

  ### transformMethod

  ClassBuilder transformMethod (MethodModel method, MethodTransform transform)
  Adds a method by transforming a method from another class.
  Implementation Note:
  The transform cannot modify the `ACC_STATIC` flag of the original method.

  Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block. Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.This method behaves as if:

  Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.Moved to a link with destination #withMethod(java.lang.classfile.constantpool.Utf8Entry,java.lang.classfile.constantpool.Utf8Entry,int,java.util.function.Consumer).Moved to a computer code block.withMethod
      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.(method.methodName(), method.methodType(), method.flags().flagMask(),Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.
                 mbMoved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

  b

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.->

  b

      mbMoved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block..

  transformMethod

      transform
      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.(method, transform))

  ;

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

      Moved out of a definition list with class notes.Moved out of a definition.Moved to a division with class block.

  Parameters:
    `method` - the method to be transformed
    `transform` - the transform to apply to the method
  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.
    - `MethodTransform`
- ≠
  public default java.lang.classfile.ClassBuilder withField(java.lang.String arg0, java.lang.constant.ClassDesc arg1, int arg2)
  Comparing master and cf

  ### withField

  default ClassBuilder withField (String name, ClassDesc descriptor, int flags)
  Adds a field, with only access flags.
  Parameters:
    `name` - the field name of the field
    `descriptor` - the symbolic field descriptor
    `flags` - the access flags for this field, as a bit mask
  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.
    - `FieldModel`
    - `FieldBuilder.withFlags(int)`
- ≠
  public default java.lang.classfile.ClassBuilder withField(java.lang.String arg0, java.lang.constant.ClassDesc arg1, java.util.function.Consumer<? super java.lang.classfile.FieldBuilder> arg2)
  Comparing master and cf

  ### withField

  default ClassBuilder withField (String name, ClassDesc descriptor, Consumer<? super FieldBuilder> handler)
  Adds a field.
  Parameters:
    `name` - the field name of the field
    `descriptor` - the symbolic field descriptor
    `handler` - handler which receives a `FieldBuilder` which can further define to supply the contents of the field
  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.
    - `FieldModel`
- ≠
  public default java.lang.classfile.ClassBuilder withField(java.lang.classfile.constantpool.Utf8Entry arg0, java.lang.classfile.constantpool.Utf8Entry arg1, int arg2)
  Comparing master and cf

  ### withField

  default ClassBuilder withField (Utf8Entry name, Utf8Entry descriptor, int flags)
  Adds a field, with only access flags.
  Parameters:
    `name` - the field name of the field
    `descriptor` - the field descriptor string
    `flags` - the access flags for this field, as a bit mask
  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.
    - `FieldModel`
    - `FieldBuilder.withFlags(int)`
- ≠
  public abstract java.lang.classfile.ClassBuilder withField(java.lang.classfile.constantpool.Utf8Entry arg0, java.lang.classfile.constantpool.Utf8Entry arg1, java.util.function.Consumer<? super java.lang.classfile.FieldBuilder> arg2)
  Comparing master and cf

  ### withField

  ClassBuilder withField (Utf8Entry name, Utf8Entry descriptor, Consumer<? super FieldBuilder> handler)
  Adds a field.
  Parameters:
    `name` - the field name of the field
    `descriptor` - the field descriptor string
    `handler` - handler which receives a `FieldBuilder` which can further define to supply the contents of the field
  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.
    - `FieldModel`
- ≠
  public default java.lang.classfile.ClassBuilder withFlags(int arg0)
  Comparing master and cf

  ### withFlags

  default ClassBuilder withFlags (int flags)
  Sets the classfile access flags of this class.
  Parameters:
    `flags` - the access flags, as a bit mask
  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.
    - `AccessFlags`
    - `AccessFlag.Location.CLASS`
- =
  public default java.lang.classfile.ClassBuilder withFlags(java.lang.reflect.AccessFlag[] arg0)
- =
  public default java.lang.classfile.ClassBuilder withInterfaceSymbols(java.lang.constant.ClassDesc[] arg0)
- ≠
  public default java.lang.classfile.ClassBuilder withInterfaceSymbols(java.util.List<java.lang.constant.ClassDesc> arg0)
  Comparing master and cf

  ### withInterfaceSymbols

  default ClassBuilder withInterfaceSymbols (List<ClassDesc> interfaces)
  Sets the interfaces of this class.
  Parameters:
    `interfaces` - the interfaces
  Returns:
    this builder
  Throws:
    `IllegalArgumentException` - if any element of `interfaces` is primitive
  See Also:
    Moved to a definition list with class notes.Moved to a definition.Moved to an unordered list with class tag-list.
    - `Interfaces`
- =
  public default java.lang.classfile.ClassBuilder withInterfaces(java.lang.classfile.constantpool.ClassEntry[] arg0)
- ≠
  public default java.lang.classfile.ClassBuilder withInterfaces(java.util.List<java.lang.classfile.constantpool.ClassEntry> arg0)
  Comparing master and cf

  ### withInterfaces

  default ClassBuilder withInterfaces (List<ClassEntry> interfaces)
  Sets the interfaces of this class.
  Parameters:
    `interfaces` - the interfaces
  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.
    - `Interfaces`
- ≠
  public default java.lang.classfile.ClassBuilder withMethod(java.lang.String arg0, java.lang.constant.MethodTypeDesc arg1, int arg2, java.util.function.Consumer<? super java.lang.classfile.MethodBuilder> arg3)
  Comparing master and cf

  ### withMethod

  default ClassBuilder withMethod (String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super MethodBuilder> handler)
  Adds a method. The bit for `ACC_STATIC` flag cannot be modified by the `handler` , and must be set through `methodFlags` .
  Parameters:
    `name` - the method name of the method
    `descriptor` - the method descriptor
    `methodFlags` - the access flags as a bit mask, with the `ACC_STATIC` bit definitely set
    `handler` - handler which receives a `MethodBuilder` which can further define to supply the contents of the method
  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.
    - `MethodModel`
- ≠
  public abstract java.lang.classfile.ClassBuilder withMethod(java.lang.classfile.constantpool.Utf8Entry arg0, java.lang.classfile.constantpool.Utf8Entry arg1, int arg2, java.util.function.Consumer<? super java.lang.classfile.MethodBuilder> arg3)
  Comparing master and cf

  ### withMethod

  ClassBuilder withMethod (Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super MethodBuilder> handler)
  Adds a method. The bit for `ACC_STATIC` flag cannot be modified by the `handler` later, and must be set through `methodFlags` .
  Parameters:
    `name` - the method name of the method
    `descriptor` - the method descriptor
    `methodFlags` - the access flags as a bit mask, with the `ACC_STATIC` bit definitely set
    `handler` - handler which receives a `MethodBuilder` which can further define to supply the contents of the method
  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.
    - `MethodModel`
- ≠
  public default java.lang.classfile.ClassBuilder withMethodBody(java.lang.String arg0, java.lang.constant.MethodTypeDesc arg1, int arg2, java.util.function.Consumer<? super java.lang.classfile.CodeBuilder> arg3)
  Comparing master and cf

  ### withMethodBody

  default ClassBuilder withMethodBody (String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super CodeBuilder> handler)
  Adds a method, with only access flags and a `CodeAttribute` . `CodeModel` . The bit for `ACC_STATIC` flag cannot be modified by the `handler` , and must be set through `methodFlags` .

  This method behaves as if:

      withMethod
      (name, descriptor, methodFlags, mb -> mb.withCode
      (handler))

  Parameters:
    `name` - the method name of the method
    `descriptor` - the method descriptor
    `methodFlags` - the access flags as a bit mask, with the `ACC_STATIC` bit definitely set
    `handler` - handler which receives a `CodeBuilder` which can define to supply the contents of the method body
  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.
    - `MethodModel`
- ≠
  public default java.lang.classfile.ClassBuilder withMethodBody(java.lang.classfile.constantpool.Utf8Entry arg0, java.lang.classfile.constantpool.Utf8Entry arg1, int arg2, java.util.function.Consumer<? super java.lang.classfile.CodeBuilder> arg3)
  Comparing master and cf

  ### withMethodBody

  default ClassBuilder withMethodBody (Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super CodeBuilder> handler)
  Adds a method, with only access flags and a `Code` attribute. `CodeModel` . The bit for `ACC_STATIC` flag cannot be modified by the `handler` later, and must be set through `methodFlags` .

  This method behaves as if:

      withMethod
      (name, descriptor, methodFlags, mb -> mb.withCode
      (handler))

  Parameters:
    `name` - the method name of the method
    `descriptor` - the method descriptor
    `methodFlags` - the access flags as a bit mask, with the `ACC_STATIC` bit definitely set
    `handler` - handler which receives a `CodeBuilder` which can define to supply the contents of the method body
  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.
    - `MethodModel`
- ≠
  public default java.lang.classfile.ClassBuilder withSuperclass(java.lang.classfile.constantpool.ClassEntry arg0)
  Comparing master and cf

  ### withSuperclass

  default ClassBuilder withSuperclass (ClassEntry superclassEntry)
  Sets the superclass of this class.
  Parameters:
    `superclassEntry` - the superclass
  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.
    - `Superclass`
- ≠
  public default java.lang.classfile.ClassBuilder withSuperclass(java.lang.constant.ClassDesc arg0)
  Comparing master and cf

  ### withSuperclass

  default ClassBuilder withSuperclass (ClassDesc desc)
  Sets the superclass of this class.
  Parameters:
    `desc` - the superclass
  Returns:
    this builder
  Throws:
    `IllegalArgumentException` - if `desc` represents a primitive type
  See Also:
    Moved to a definition list with class notes.Moved to a definition.Moved to an unordered list with class tag-list.
    - `Superclass`
- ≠
  public default java.lang.classfile.ClassBuilder withVersion(int arg0, int arg1)
  Comparing master and cf

  ### withVersion

  default ClassBuilder withVersion (int major, int minor)
  Sets the classfile version of this class.
  Parameters:
    `major` - the major version number
    `minor` - the minor version number
  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.
    - `ClassFileVersion`

## Summary

Differences
| Elements | Comments | Descriptions | Total
Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed
--- | --- | --- | --- | --- | --- | --- | --- | ---
ClassBuilder |  |  |  |  |  |  | 6 | 8 | 3 | 17
transformField(FieldModel,FieldTransform) |  |  |  |  |  |  | 5 | 1 | 7 | 13
transformMethod(MethodModel,MethodTransform) |  |  |  |  |  |  | 5 |  | 7 | 12
withField(String,ClassDesc,int) |  |  |  |  |  |  | 9 |  | 2 | 11
withField(String,ClassDesc,Consumer) |  |  |  |  |  |  | 6 | 1 | 3 | 10
withField(Utf8Entry,Utf8Entry,int) |  |  |  |  |  |  | 9 |  | 2 | 11
withField(Utf8Entry,Utf8Entry,Consumer) |  |  |  |  |  |  | 7 |  | 2 | 9
withFlags(int) |  |  |  |  |  |  | 6 |  | 1 | 7
withInterfaceSymbols(List) |  |  |  |  |  |  | 7 |  |  | 7
withInterfaces(List) |  |  |  |  |  |  | 5 |  |  | 5
withMethod(String,MethodTypeDesc,int,Consumer) |  |  |  |  |  |  | 13 |  | 2 | 15
withMethod(Utf8Entry,Utf8Entry,int,Consumer) |  |  |  |  |  |  | 13 |  | 2 | 15
withMethodBody(String,MethodTypeDesc,int,Consumer) |  |  |  |  |  |  | 17 | 1 | 3 | 21
withMethodBody(Utf8Entry,Utf8Entry,int,Consumer) |  |  |  |  |  |  | 17 | 1 | 3 | 21
withSuperclass(ClassEntry) |  |  |  |  |  |  | 5 |  |  | 5
withSuperclass(ClassDesc) |  |  |  |  |  |  | 5 |  |  | 5
withVersion(int,int) |  |  |  |  |  |  | 6 |  | 1 | 7
Total |  |  |  |  |  |  | 141 | 12 | 38 | 191