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

# Interface ModuleAttribute

All Superinterfaces:
  `AttributePREVIEW<ModuleAttributePREVIEW>`, `ClassElementPREVIEW`, `ClassFileElementPREVIEW`, `WritableElementPREVIEW<ModuleAttributePREVIEW>`

public sealed interface ModuleAttribute extends AttributePREVIEW<ModuleAttributePREVIEW>, ClassElementPREVIEW
`ModuleAttribute` is a preview API of the Java platform.
Programs can only use `ModuleAttribute` 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 `Module` attribute 4.7.25, which can appear on classes that represent module descriptors. Delivered as a `ClassElement`PREVIEW when traversing the elements of a `ClassModel`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.

The attribute was introduced in the Java SE Platform version 9.

Since:
  22

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static interface`
  `ModuleAttribute.ModuleAttributeBuilderPREVIEW`
  Preview.
  A builder for module attributes.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<ModuleExportInfoPREVIEW>`
  `exports()`
  Returns the packages exported by this module.
  `default boolean`
  `has(AccessFlag flag)`
  Tests presence of module flag
  `default Set<AccessFlag>`
  `moduleFlags()`
  Returns the the module flags of the module, as a set of enum constants.
  `int`
  `moduleFlagsMask()`
  Returns the the module flags of the module, as a bit mask.
  `ModuleEntryPREVIEW`
  `moduleName()`
  Returns the name of the module.
  `Optional<Utf8EntryPREVIEW>`
  `moduleVersion()`
  Returns the version of the module, if present.
  `static ModuleAttributePREVIEW`
  `of(ModuleEntryPREVIEW moduleName, int moduleFlags, Utf8EntryPREVIEW moduleVersion, Collection<ModuleRequireInfoPREVIEW> requires, Collection<ModuleExportInfoPREVIEW> exports, Collection<ModuleOpenInfoPREVIEW> opens, Collection<ClassEntryPREVIEW> uses, Collection<ModuleProvideInfoPREVIEW> provides)`
  Returns a `Module` attribute.
  `static ModuleAttributePREVIEW`
  `of(ModuleEntryPREVIEW moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler)`
  Returns a `Module` attribute.
  `static ModuleAttributePREVIEW`
  `of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler)`
  Returns a `Module` attribute.
  `List<ModuleOpenInfoPREVIEW>`
  `opens()`
  Returns the packages opened by this module.
  `List<ModuleProvideInfoPREVIEW>`
  `provides()`
  Returns the service implementations provided by this module.
  `List<ModuleRequireInfoPREVIEW>`
  `requires()`
  Returns the modules required by this module.
  `List<ClassEntryPREVIEW>`
  `uses()`
  Returns the services used by this module.

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

  `attributeMapper, attributeName`

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

  `writeTo`

- ## Method Details

  - ### moduleName

    ModuleEntryPREVIEW moduleName()
    Returns the name of the module.
    Returns:
      the name of the module

  - ### moduleFlagsMask

    int moduleFlagsMask()
    Returns the the module flags of the module, as a bit mask.
    Returns:
      the the module flags of the module, as a bit mask

  - ### moduleFlags

    default Set<AccessFlag> moduleFlags()
    Returns the the module flags of the module, as a set of enum constants.
    Returns:
      the the module flags of the module, as a set of enum constants

  - ### has

    default boolean has(AccessFlag flag)
    Tests presence of module flag
    Parameters:
      `flag` - the module flag
    Returns:
      true if the flag is set

  - ### moduleVersion

    Optional<Utf8EntryPREVIEW> moduleVersion()
    Returns the version of the module, if present.
    Returns:
      the version of the module, if present

  - ### requires

    List<ModuleRequireInfoPREVIEW> requires()
    Returns the modules required by this module.
    Returns:
      the modules required by this module

  - ### exports

    List<ModuleExportInfoPREVIEW> exports()
    Returns the packages exported by this module.
    Returns:
      the packages exported by this module

  - ### opens

    List<ModuleOpenInfoPREVIEW> opens()
    Returns the packages opened by this module.
    Returns:
      the packages opened by this module

  - ### uses

    List<ClassEntryPREVIEW> uses()
    Returns the services used by this module. Services may be discovered via `ServiceLoader`.
    Returns:
      the services used by this module

  - ### provides

    List<ModuleProvideInfoPREVIEW> provides()
    Returns the service implementations provided by this module.
    Returns:
      the service implementations provided by this module

  - ### of

    static ModuleAttributePREVIEW of(ModuleEntryPREVIEW moduleName, int moduleFlags, Utf8EntryPREVIEW moduleVersion, Collection<ModuleRequireInfoPREVIEW> requires, Collection<ModuleExportInfoPREVIEW> exports, Collection<ModuleOpenInfoPREVIEW> opens, Collection<ClassEntryPREVIEW> uses, Collection<ModuleProvideInfoPREVIEW> provides)
    Returns a `Module` attribute.
    Parameters:
      `moduleName` - the module name
      `moduleFlags` - the module flags
      `moduleVersion` - the module version
      `requires` - the required packages
      `exports` - the exported packages
      `opens` - the opened packages
      `uses` - the consumed services
      `provides` - the provided services
    Returns:
      a `Module` attribute

  - ### of

    static ModuleAttributePREVIEW of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler)
    Returns a `Module` attribute.
    Parameters:
      `moduleName` - the module name
      `attrHandler` - a handler that receives a `ModuleAttribute.ModuleAttributeBuilder`PREVIEW
    Returns:
      a `Module` attribute

  - ### of

    static ModuleAttributePREVIEW of(ModuleEntryPREVIEW moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler)
    Returns a `Module` attribute.
    Parameters:
      `moduleName` - the module name
      `attrHandler` - a handler that receives a `ModuleAttribute.ModuleAttributeBuilder`PREVIEW
    Returns:
      a `Module` attribute