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

Module java.base
Package java.lang.classfilePREVIEW

# Interface CodeModel

All Superinterfaces:
  `AttributedElementPREVIEW`, `ClassFileElementPREVIEW`, `CompoundElementPREVIEW<CodeElementPREVIEW>`, `Iterable<CodeElementPREVIEW>`, `MethodElementPREVIEW`

All Known Subinterfaces:
  `CodeAttributePREVIEW`

public sealed interface CodeModel extends CompoundElementPREVIEW<CodeElementPREVIEW>, AttributedElementPREVIEW, MethodElementPREVIEW permits CodeAttributePREVIEW (not exhaustive)
`CodeModel` is a preview API of the Java platform.
Programs can only use `CodeModel` 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 body of a method (the `Code` attribute). The instructions of the method body are accessed via a streaming view (e.g., `CompoundElement.elements()`PREVIEW).

Since:
  22

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<ExceptionCatchPREVIEW>`
  `exceptionHandlers()`
  Returns the exception table of the method.
  `int`
  `maxLocals()`
  Returns the maximum size of the local variable table.
  `int`
  `maxStack()`
  Returns the maximum size of the operand stack.
  `Optional<MethodModelPREVIEW>`
  `parent()`
  Returns the enclosing method, if known.

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

  `attributes, findAttribute, findAttributes`

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

  `elementList, elements, elementStream, forEachElement, iterator`

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

  `forEach, spliterator`

- ## Method Details

  - ### maxLocals

    int maxLocals()
    Returns the maximum size of the local variable table.
    Returns:
      the maximum size of the local variable table

  - ### maxStack

    int maxStack()
    Returns the maximum size of the operand stack.
    Returns:
      the maximum size of the operand stack

  - ### parent

    Optional<MethodModelPREVIEW> parent()
    Returns the enclosing method, if known.
    Returns:
      the enclosing method, if known

  - ### exceptionHandlers

    List<ExceptionCatchPREVIEW> exceptionHandlers()
    Returns the exception table of the method. The exception table is also modeled by `ExceptionCatch`PREVIEW elements in the streaming view.
    Returns:
      the exception table of the method