Package Summary Overview Summary

Module java.base
Package java.lang.classfile.attributePREVIEW

# Interface CodeAttribute

All Superinterfaces:
  `AttributePREVIEW<CodeAttributePREVIEW>`, `AttributedElementPREVIEW`, `ClassFileElementPREVIEW`, `CodeModelPREVIEW`, `CompoundElementPREVIEW<CodeElementPREVIEW>`, `Iterable<CodeElementPREVIEW>`, `MethodElementPREVIEW`, `WritableElementPREVIEW<CodeAttributePREVIEW>`

public sealed interface CodeAttribute extends AttributePREVIEW<CodeAttributePREVIEW>, CodeModelPREVIEW
`CodeAttribute` is a preview API of the Java platform.
Programs can only use `CodeAttribute` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models the `Code` attribute 4.7.3, appears on non-native, non-abstract methods and contains the bytecode of the method body. Delivered as a `MethodElement`PREVIEW when traversing the elements of a `MethodModel`PREVIEW.

The attribute does not permit multiple instances in a given location. Subsequent occurrence of the attribute takes precedence during the attributed element build or transformation.

Since:
  22

- ## Method Summary

  Modifier and Type
  Method
  Description
  `byte[]`
  `codeArray()`
  Returns the bytes (bytecode) of the code array.
  `int`
  `codeLength()`
  Returns The length of the code array in bytes.
  `int`
  `labelToBci (LabelPREVIEW label)`
  Returns the position of the `Label` in the `codeArray` or -1 if the `Label` does not point to the `codeArray`.

  ### Methods declared in interface java.lang.classfile.AttributePREVIEW

  `attributeMapper, attributeName`

  ### Methods declared in interface java.lang.classfile.AttributedElementPREVIEW

  `attributes, findAttribute, findAttributes`

  ### Methods declared in interface java.lang.classfile.CodeModelPREVIEW

  `exceptionHandlers, maxLocals, maxStack, parent`

  ### Methods declared in interface java.lang.classfile.CompoundElementPREVIEW

  `elementList, elements, elementStream, forEachElement, iterator`

  ### Methods declared in interface java.lang.Iterable

  `forEach, spliterator`

  ### Methods declared in interface java.lang.classfile.WritableElementPREVIEW

  `writeTo`

- ## Method Details

  - ### codeLength

    int codeLength()
    Returns The length of the code array in bytes.
    Returns:
      The length of the code array in bytes

  - ### codeArray

    byte[] codeArray()
    Returns the bytes (bytecode) of the code array.
    Returns:
      the bytes (bytecode) of the code array

  - ### labelToBci

    int labelToBci (LabelPREVIEW label)
    Returns the position of the `Label` in the `codeArray` or -1 if the `Label` does not point to the `codeArray`.
    Parameters:
      `label` - a marker for a position within this `CodeAttribute`
    Returns:
      the position of the `Label` in the `codeArray` or -1 if the `Label` does not point to the `codeArray`