FieldModel (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang.classfile, interface: FieldModel
Keywords: java.lang.classfile.FieldModel interface

# Interface FieldModel

All Superinterfaces:
  `AttributedElement, ClassElement, ClassFileElement, CompoundElement<FieldElement>, Iterable<FieldElement>`

public sealed interface FieldModel extends CompoundElement<FieldElement>, AttributedElement, ClassElement
Models a field. A field can be viewed as a composition of `FieldElement`s, or by random access via accessor methods if only specific parts of the field is needed.

Fields can be obtained from `ClassModel.fields()`, or in the traversal of member elements of a class.

`ClassBuilder.withField(String, ClassDesc, Consumer)` is the main way to construct fields. `ClassBuilder.transformField(FieldModel, FieldTransform)` allows creating a new field by selectively processing the original field elements and directing the results to a field builder.

All field attributes are accessible as member elements.

See Java Virtual Machine Specification:
  4.5 Fields
Since:
  24
See Also:
  - `ClassModel.fields()`
  - `FieldTransform`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Utf8Entry`
  `fieldName()`
  Returns the name of this field.
  `Utf8Entry`
  `fieldType()`
  Returns the field descriptor string of this field.
  `default ClassDesc`
  `fieldTypeSymbol()`
  Returns the field type, as a symbolic descriptor.
  `AccessFlags`
  `flags()`
  Returns the access flags.
  `Optional<ClassModel>`
  `parent()`
  Returns the class model this field is a member of, if known.

  ### Methods declared in interface AttributedElement

  `attributes, findAttribute, findAttributes`
  Modifier and Type
  Method
  Description
  `List<Attribute<?>>`
  `attributes()`
  Returns the attributes of this structure.
  `default <T extends Attribute<T>>
  Optional<T>`
  `findAttribute(AttributeMapper<T> attr)`
  Finds an attribute by name.
  `default <T extends Attribute<T>>
  List<T>`
  `findAttributes(AttributeMapper<T> attr)`
  Finds attributes by name.

  ### Methods declared in interface CompoundElement

  `elementList, elementStream, forEach, iterator, toDebugString`
  Modifier and Type
  Method
  Description
  `default List<FieldElement>`
  `elementList()`
  Returns a `List` containing all member elements in this compound element.
  `default Stream<FieldElement>`
  `elementStream()`
  Returns a `Stream` containing all member elements in this compound element.
  `void`
  `forEach(Consumer<? super FieldElement> consumer)`
  Invokes the provided handler with each member element in this compound element.
  `default Iterator<FieldElement>`
  `iterator()`
  Returns an `Iterator` describing all member elements in this compound element.
  `default String`
  `toDebugString()`
  Returns a text representation of the compound element and its contents for debugging purposes.

  ### Methods declared in interface Iterable

  `spliterator`
  Modifier and Type
  Method
  Description
  `default Spliterator<FieldElement>`
  `spliterator()`
  Creates a `Spliterator` over the elements described by this `Iterable`.

- ## Method Details

  - ### flags

    AccessFlags flags()
    Returns the access flags.
    Returns:
      the access flags
    See Also:
      - `AccessFlag.Location.FIELD`

  - ### parent

    Optional<ClassModel> parent()
    Returns the class model this field is a member of, if known.
    Returns:
      the class model this field is a member of, if known

  - ### fieldName

    Utf8Entry fieldName()
    Returns the name of this field.
    Returns:
      the name of this field

  - ### fieldType

    Utf8Entry fieldType()
    Returns the field descriptor string of this field.
    Returns:
      the field descriptor string of this field

  - ### fieldTypeSymbol

    default ClassDesc fieldTypeSymbol()
    Returns the field type, as a symbolic descriptor.
    Returns:
      the field type, as a symbolic descriptor