Module java.base
Package java.lang.classfile

# Interface CompoundElement

≠
public abstract sealed interface CompoundElement<E>
extends java.lang.Iterable<E>, java.lang.classfile.ClassFileElement
permits java.lang.classfile.ClassModel, java.lang.classfile.CodeModel, java.lang.classfile.FieldModel, java.lang.classfile.MethodModel, jdk.internal.classfile.impl.AbstractUnboundModel<E>
Comparing master and cf

Type Parameters:
  `E` - the member element type

All Superinterfaces:
  `ClassFileElement, Iterable<E>`

All Known Subinterfaces:
  `ClassModel, CodeAttribute, CodeModel, FieldModel, MethodModel`

public sealed interface CompoundElement<E extends ClassFileElement> extends ClassFileElement, Iterable<E> permits ClassModel, CodeModel, FieldModel, MethodModel (not exhaustive)
A `ClassFileElement` that has complex structure defined in terms of other classfile elements, such as a method, field, method body, or entire class. When encountering a CompoundElement, clients have the option to treat the element as a single entity (e.g., an entire method) or to traverse the contents of that element with the methods in this class (e.g., `forEach(Consumer)` , etc.) `class` file structure that can be viewed as a composition of its member structures. `CompoundElement` allows users to traverse these member elements with `forEach(Consumer)` or `elementStream()` , or buffer the elements obtained from the traversal through `iterator()` or `elementList()` .

Unless otherwise specified, all member elements of compatible type will be presented during the traversal if they exist in this element. Some member elements specify that they may appear at most once in this element; if such elements are presented multiple times, the latest occurrence is authentic and all previous occurrences should be ignored.

`CompoundElement` s can be constructed by `ClassFileBuilder` s. `ClassFileBuilder.transform(CompoundElement, ClassFileTransform)` provides an easy way to create a new structure by selectively processing the original member structures and directing the results to the builder.Moved to a paragraph.

Sealed Class Hierarchy Graph:
Since:
  24
See Also:
  Moved to a definition list with class notes.Moved to a definition.Moved to an unordered list with class tag-list.
  - Membership Elements
  - `ClassFileBuilder`

## Methods

- ≠
  public default java.util.List<E> elementList()
  Comparing master and cf

  ### elementList

  default List<E> elementList()
  Returns an a `List` containing all the member elements contained in this compound element.
  Returns:
    an a `List` containing all the member elements contained in this compound element
- ≠
  public default java.util.stream.Stream<E> elementStream()
  Comparing master and cf

  ### elementStream

  default Stream<E> elementStream()
  Returns a `Stream` containing all the member elements contained in this compound element.
  Returns:
    a `Stream` containing all the member elements contained in this compound element
- ≠
  public abstract void forEach(java.util.function.Consumer<? super E> arg0)
  Comparing master and cf

  ### forEach

  void forEach (Consumer<? super E> consumer)
  Invoke Invokes the provided handler with each member element contained in this compound element.
  Specified by:
    `forEach` in interface `Iterable<E extends ClassFileElement>`
  Parameters:
    `consumer` - the handler
- ≠
  public default java.util.Iterator<E> iterator()
  Comparing master and cf

  ### iterator

  default Iterator<E> iterator()
  Returns an `Iterator` describing all the member elements contained in this compound element.
  Specified by:
    `iterator` in interface `Iterable<E extends ClassFileElement>`
  Returns:
    an `Iterator` describing all the member elements contained in this compound element
- ≠
  public default java.lang.String toDebugString()
  Comparing master and cf

  ### toDebugString

  default String toDebugString()
  Returns a text representation of the compound element and its contents for debugging purposes. The format, structure and exact contents of the returned string are not specified and may change at any time in the future.
  Returns:
    a text representation of the compound element and its contents for debugging purposes

## Summary

Differences
| Elements | Comments | Descriptions | Total
Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed
--- | --- | --- | --- | --- | --- | --- | --- | ---
CompoundElement |  |  |  |  |  |  | 15 | 2 | 3 | 20
elementList() |  |  |  |  |  |  |  | 4 | 2 | 6
elementStream() |  |  |  |  |  |  |  | 2 | 2 | 4
forEach(Consumer) |  |  |  |  |  |  | 2 | 1 | 1 | 4
iterator() |  |  |  |  |  |  |  | 2 | 2 | 4
Total |  |  |  |  |  |  | 17 | 11 | 10 | 38