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

# Interface AttributedElement

All Superinterfaces:
  `ClassFileElementPREVIEW`

All Known Subinterfaces:
  `ClassModelPREVIEW`, `CodeAttributePREVIEW`, `CodeModelPREVIEW`, `FieldModelPREVIEW`, `MethodModelPREVIEW`, `RecordComponentInfoPREVIEW`

public sealed interface AttributedElement extends ClassFileElementPREVIEW permits ClassModelPREVIEW, CodeModelPREVIEW, FieldModelPREVIEW, MethodModelPREVIEW, RecordComponentInfoPREVIEW (not exhaustive)
`AttributedElement` is a preview API of the Java platform.
Programs can only use `AttributedElement` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A `ClassFileElement`PREVIEW describing an entity that has attributes, such as a class, field, method, code attribute, or record component.

Sealed Class Hierarchy Graph:
Since:
  22

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<AttributePREVIEW<?>>`
  `attributes()`
  Returns the attributes of this element.
  `default <T extends AttributePREVIEW<T>>
  Optional<T>`
  `findAttribute(AttributeMapperPREVIEW<T> attr)`
  Finds an attribute by name.
  `default <T extends AttributePREVIEW<T>>
  List<T>`
  `findAttributes(AttributeMapperPREVIEW<T> attr)`
  Finds one or more attributes by name.

- ## Method Details

  - ### attributes

    List<AttributePREVIEW<?>> attributes()
    Returns the attributes of this element.
    Returns:
      the attributes of this element

  - ### findAttribute

    default <T extends AttributePREVIEW<T>> Optional<T> findAttribute(AttributeMapperPREVIEW<T> attr)
    Finds an attribute by name.
    Type Parameters:
      `T` - the type of the attribute
    Parameters:
      `attr` - the attribute mapper
    Returns:
      the attribute, or an empty Optional if the attribute is not present

  - ### findAttributes

    default <T extends AttributePREVIEW<T>> List<T> findAttributes(AttributeMapperPREVIEW<T> attr)
    Finds one or more attributes by name.
    Type Parameters:
      `T` - the type of the attribute
    Parameters:
      `attr` - the attribute mapper
    Returns:
      the attributes, or an empty List if the attribute is not present