W3cubDocs

/OpenJDK 25

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.

CompoundElements can be constructed by ClassFileBuilders. 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:
Sealed class hierarchy graph for CompoundElementSealed class hierarchy graph for CompoundElement
Since:
24
See Also:

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

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/CompoundElement.html