Attribute<EnclosingMethodAttribute>, ClassElement, ClassFileElementpublic sealed interface EnclosingMethodAttribute extends Attribute<EnclosingMethodAttribute>, ClassElement
EnclosingMethod attribute (JVMS 4.7.7), which indicates that this class is a local or anonymous class, and indicates the enclosing method or constructor of this class if this class is enclosed in exactly one method or constructor. This attribute only appears on classes, and does not permit multiple instances in a class. It has a data dependency on the constant pool.
The attribute was introduced in the Java SE Platform version 5.0, major version 49.
EnclosingMethod Attribute| Modifier and Type | Method | Description |
|---|---|---|
ClassEntry |
enclosingClass() |
Returns the class that encloses the declaration of the current class. |
Optional |
enclosingMethod() |
Returns the name and type of the enclosing method, if the class is immediately enclosed by exactly one method or constructor. |
default Optional |
enclosingMethodName() |
Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor. |
default Optional |
enclosingMethodType() |
Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor. |
default Optional |
enclosingMethodTypeSymbol() |
Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor. |
static EnclosingMethodAttribute |
of |
Returns an EnclosingMethod attribute. |
static EnclosingMethodAttribute |
of |
Returns an EnclosingMethod attribute. |
attributeMapper, attributeName
ClassEntry enclosingClass()
enclosingMethod() is present, this is the declaring class of that enclosing method or constructor.Optional<NameAndTypeEntry> enclosingMethod()
default Optional<Utf8Entry> enclosingMethodName()
default Optional<Utf8Entry> enclosingMethodType()
default Optional<MethodTypeDesc> enclosingMethodTypeSymbol()
static EnclosingMethodAttribute of(ClassEntry className, Optional<NameAndTypeEntry> method)
EnclosingMethod attribute.className - the class namemethod - the name and type of the enclosing method or Optional.empty() if the class is not immediately enclosed by exactly one method or constructorEnclosingMethod attributestatic EnclosingMethodAttribute of(ClassDesc className, Optional<String> methodName, Optional<MethodTypeDesc> methodType)
EnclosingMethod attribute.className - the class namemethodName - the name of the enclosing method or Optional.empty() if the class is not immediately enclosed by exactly one method or constructormethodType - the type of the enclosing method or Optional.empty() if the class is not immediately enclosed by exactly one method or constructorEnclosingMethod attributeIllegalArgumentException - if className represents a primitive type
© 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/attribute/EnclosingMethodAttribute.html