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

# Interface MethodSignature

public sealed interface MethodSignature
Models the generic signature of a method or constructor, as defined by JVMS 4.7.9.1.

See Java Language Specification:
  8.4 Method Declarations
  8.8 Constructor Declarations
See Java Virtual Machine Specification:
  4.7.9.1 Signatures
Since:
  24
See Also:
  - `Executable`
  - `SignatureAttribute`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<Signature>`
  `arguments()`
  Returns the signatures of the parameters of this method or constructor, may be empty.
  `static MethodSignature`
  `of(Signature result, Signature... arguments)`
  Returns a method signature with no type parameter or exception type.
  `static MethodSignature`
  `of(MethodTypeDesc methodDescriptor)`
  Returns a method signature for a raw method descriptor.
  `static MethodSignature`
  `of(List<Signature.TypeParam> typeParameters, List<Signature.ThrowableSig> exceptions, Signature result, Signature... arguments)`
  Returns a method signature.
  `static MethodSignature`
  `parseFrom(String methodSignature)`
  Parses a raw method signature string into a `MethodSignature`.
  `Signature`
  `result()`
  Returns the signatures of the return value of this method.
  `String`
  `signatureString()`
  Returns the raw signature string.
  `List<Signature.ThrowableSig>`
  `throwableSignatures()`
  Returns the signatures of the exceptions thrown by this method or constructor.
  `List<Signature.TypeParam>`
  `typeParameters()`
  Returns the type parameters of this method or constructor, may be empty.

- ## Method Details

  - ### typeParameters

    List<Signature.TypeParam> typeParameters()
    Returns the type parameters of this method or constructor, may be empty.
    Returns:
      the type parameters of this method or constructor, may be empty
    See Java Language Specification:
      8.4.4 Generic Methods
      8.8.4 Generic Constructors
    See Also:
      - `Executable.getTypeParameters()`

  - ### arguments

    List<Signature> arguments()
    Returns the signatures of the parameters of this method or constructor, may be empty. The parameters may differ from those in the method descriptor because some synthetic or implicit parameters are omitted.
    Returns:
      the signatures of the parameters of this method or constructor, may be empty
    See Java Language Specification:
      8.4.1 Formal Parameters
      8.8.1 Formal Parameters
    See Also:
      - `Executable.getGenericParameterTypes()`

  - ### result

    Signature result()
    Returns the signatures of the return value of this method. For constructors, this returns a signature representing `void`.
    Returns:
      the signatures of the return value of this method
    See Java Language Specification:
      8.4.5 Method Result
    See Also:
      - `Method.getGenericReturnType()`

  - ### throwableSignatures

    List<Signature.ThrowableSig> throwableSignatures()
    Returns the signatures of the exceptions thrown by this method or constructor.
    Returns:
      the signatures of the exceptions thrown by this method or constructor
    See Java Language Specification:
      8.4.6 Method Throws
      8.8.5 Constructor Throws
    See Also:
      - `Executable.getGenericExceptionTypes()`

  - ### signatureString

    String signatureString()
    Returns the raw signature string.
    Returns:
      the raw signature string

  - ### of

    static MethodSignature of(MethodTypeDesc methodDescriptor)
    Returns a method signature for a raw method descriptor. The resulting signature has no type parameter or exception type declared.
    Parameters:
      `methodDescriptor` - the method descriptor
    Returns:
      a method signature for a raw method descriptor

  - ### of

    static MethodSignature of(Signature result, Signature... arguments)
    Returns a method signature with no type parameter or exception type. The parameters may differ from those in the method descriptor because some synthetic or implicit parameters are omitted.
    Parameters:
      `result` - signature for the return type
      `arguments` - signatures for the method parameters
    Returns:
      a method signature with no type parameter or exception type

  - ### of

    static MethodSignature of(List<Signature.TypeParam> typeParameters, List<Signature.ThrowableSig> exceptions, Signature result, Signature... arguments)
    Returns a method signature. The parameters may differ from those in the method descriptor because some synthetic or implicit parameters are omitted.
    Parameters:
      `typeParameters` - signatures for the type parameters
      `exceptions` - signatures for the exceptions
      `result` - signature for the return type
      `arguments` - signatures for the method parameters
    Returns:
      a method signature

  - ### parseFrom

    static MethodSignature parseFrom(String methodSignature)
    Parses a raw method signature string into a `MethodSignature`.
    Parameters:
      `methodSignature` - the raw method signature string
    Returns:
      the parsed method signature
    Throws:
      `IllegalArgumentException` - if the string is not a valid method signature string