SignatureAttribute (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang.classfile.attribute, interface: SignatureAttribute
Keywords: java.lang.classfile.attribute.SignatureAttribute interface

# Interface SignatureAttribute

All Superinterfaces:
  `Attribute<SignatureAttribute>, ClassElement, ClassFileElement, FieldElement, MethodElement`

public sealed interface SignatureAttribute extends Attribute<SignatureAttribute>, ClassElement, MethodElement, FieldElement
Models the `Signature` attribute (JVMS 4.7.9), which indicates the generic signature of this structure.

This attribute appears on classes, fields, methods, and record components, and does not permit multiple instances in one structure. It has a data dependency on the constant pool.

The attribute was introduced in the Java SE Platform version 5.0, major version 49.

See Java Virtual Machine Specification:
  4.7.9 The `Signature` Attribute
Since:
  24
See Also:
  - `Signature`
  - `ClassSignature`
  - `MethodSignature`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default ClassSignature`
  `asClassSignature()`
  Parses the signature string as a class signature.
  `default MethodSignature`
  `asMethodSignature()`
  Parse the signature string as a method signature.
  `default Signature`
  `asTypeSignature()`
  Parses the signature string as a Java type signature.
  `static SignatureAttribute`
  `of(ClassSignature classSignature)`
  Returns a `Signature` attribute for a class.
  `static SignatureAttribute`
  `of(Utf8Entry signature)`
  Returns a `Signature` attribute.
  `static SignatureAttribute`
  `of(MethodSignature methodSignature)`
  Returns a `Signature` attribute for a method.
  `static SignatureAttribute`
  `of(Signature signature)`
  Returns a `Signature` attribute for a field or a record component.
  `Utf8Entry`
  `signature()`
  Returns the signature string for the class, method, field, or record component.

  ### Methods declared in interface Attribute

  `attributeMapper, attributeName`
  Modifier and Type
  Method
  Description
  `AttributeMapper<SignatureAttribute>`
  `attributeMapper()`
  Returns the `AttributeMapper` associated with this attribute.
  `Utf8Entry`
  `attributeName()`
  Returns the name of the attribute.

- ## Method Details

  - ### signature

    Utf8Entry signature()
    Returns the signature string for the class, method, field, or record component. It is a class signature string if this attribute is on a class, a method signature string if this attribute is on a method, or a field signature string if this attribute is on a field or a record component.
    Returns:
      the signature string for the class, method, field, or record component
    See Java Virtual Machine Specification:
      4.7.9.1 Signatures

  - ### asClassSignature

    default ClassSignature asClassSignature()
    Parses the signature string as a class signature.
    Returns:
      the class signature
    Throws:
      `IllegalArgumentException` - if the signature string is not a valid class signature string

  - ### asMethodSignature

    default MethodSignature asMethodSignature()
    Parse the signature string as a method signature.
    Returns:
      the method signature
    Throws:
      `IllegalArgumentException` - if the signature string is not a valid method signature string

  - ### asTypeSignature

    default Signature asTypeSignature()
    Parses the signature string as a Java type signature.
    Returns:
      the type signature
    Throws:
      `IllegalArgumentException` - if the signature string is not a valid Java type signature string
    See Also:
      - `Field.getGenericType()`
      - `RecordComponent.getGenericType()`

  - ### of

    static SignatureAttribute of(ClassSignature classSignature)
    Returns a `Signature` attribute for a class.
    Parameters:
      `classSignature` - the class signature
    Returns:
      a `Signature` attribute for a class

  - ### of

    static SignatureAttribute of(MethodSignature methodSignature)
    Returns a `Signature` attribute for a method.
    Parameters:
      `methodSignature` - the method signature
    Returns:
      a `Signature` attribute for a method

  - ### of

    static SignatureAttribute of(Signature signature)
    Returns a `Signature` attribute for a field or a record component.
    Parameters:
      `signature` - the Java type signature
    Returns:
      a `Signature` attribute for a field or a record component

  - ### of

    static SignatureAttribute of(Utf8Entry signature)
    Returns a `Signature` attribute.
    Parameters:
      `signature` - the signature string
    Returns:
      a `Signature` attribute