# Interface CompoundElement<E extends ClassFileElement>

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 `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.

Sealed Class Hierarchy Graph:
Since:
  24
See Also:
  - Membership Elements
  - `ClassFileBuilder`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default List<E>`
  `elementList()`
  Returns a `List` containing all member elements in this compound element.
  `default Stream<E>`
  `elementStream()`
  Returns a `Stream` containing all member elements in this compound element.
  `void`
  `forEach(Consumer<? super E> consumer)`
  Invokes the provided handler with each member element in this compound element.
  `default Iterator<E>`
  `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 java.lang.Iterable

  `spliterator`

- ## Method Details

  - ### forEach

    void forEach(Consumer<? super E> consumer)
    Invokes the provided handler with each member element in this compound element.
    Specified by:
      `forEach` in interface `Iterable<E extends ClassFileElement>`
    Parameters:
      `consumer` - the handler

  - ### iterator

    default Iterator<E> iterator()
    Returns an `Iterator` describing all member elements in this compound element.
    Specified by:
      `iterator` in interface `Iterable<E extends ClassFileElement>`
    Returns:
      an `Iterator` describing all member elements in this compound element

  - ### elementStream

    default Stream<E> elementStream()
    Returns a `Stream` containing all member elements in this compound element.
    Returns:
      a `Stream` containing all member elements in this compound element

  - ### elementList

    default List<E> elementList()
    Returns a `List` containing all member elements in this compound element.
    Returns:
      a `List` containing all member elements in this compound element

  - ### 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