* #### isNamed
public boolean isNamed()
Returns `true` if this module is a named module.
Returns:
`true` if this is a named module
See Also:
[ClassLoader.getUnnamedModule()](../../java/lang/ClassLoader.html#getUnnamedModule%28%29)
* #### getName
public [String](../../java/lang/String.html "class in java.lang") getName()
Returns the module name or `null` if this module is an unnamed module.
Returns:
The module name
* #### getClassLoader
public [ClassLoader](../../java/lang/ClassLoader.html "class in java.lang") getClassLoader()
Returns the `ClassLoader` for this module.
If there is a security manager then its `checkPermission` method if first called with a `RuntimePermission("getClassLoader")` permission to check that the caller is allowed to get access to the class loader.
Returns:
The class loader for this module
Throws:
`[SecurityException](../../java/lang/SecurityException.html "class in java.lang")` \- If denied by the security manager
* #### getDescriptor
public [ModuleDescriptor](../../java/lang/module/ModuleDescriptor.html "class in java.lang.module") getDescriptor()
Returns the module descriptor for this module or `null` if this module is an unnamed module.
Returns:
The module descriptor for this module
* #### getLayer
public [ModuleLayer](../../java/lang/ModuleLayer.html "class in java.lang") getLayer()
Returns the module layer that contains this module or `null` if this module is not in a module layer. A module layer contains named modules and therefore this method always returns `null` when invoked on an unnamed module.
[Dynamic modules](reflect/Proxy.html#dynamicmodule) are named modules that are generated at runtime. A dynamic module may or may not be in a module layer.
Returns:
The module layer that contains this module
See Also:
[Proxy](../../java/lang/reflect/Proxy.html "class in java.lang.reflect")
* #### canRead
public boolean canRead([Module](../../java/lang/Module.html "class in java.lang") other)
Indicates if this module reads the given module. This method returns`true` if invoked to test if this module reads itself. It also returns `true` if invoked on an unnamed module (as unnamed modules read all modules).
Parameters:
`other` \- The other module
Returns:
`true` if this module reads `other`
See Also:
[addReads(Module)](../../java/lang/Module.html#addReads%28java.lang.Module%29)
* #### addReads
public [Module](../../java/lang/Module.html "class in java.lang") addReads([Module](../../java/lang/Module.html "class in java.lang") other)
If the caller's module is this module then update this module to read the given module. This method is a no-op if `other` is this module (all modules read themselves), this module is an unnamed module (as unnamed modules read all modules), or this module already reads `other`.
Implementation Note:
_Read edges_ added by this method are _weak_ and do not prevent `other` from being GC'ed when this module is strongly reachable.
Parameters:
`other` \- The other module
Returns:
this module
Throws:
`[IllegalCallerException](../../java/lang/IllegalCallerException.html "class in java.lang")` \- If this is a named module and the caller's module is not this module
See Also:
[canRead(java.lang.Module)](../../java/lang/Module.html#canRead%28java.lang.Module%29)
* #### isExported
public boolean isExported([String](../../java/lang/String.html "class in java.lang") pn,
[Module](../../java/lang/Module.html "class in java.lang") other)
Returns `true` if this module exports the given package to at least the given module.
This method returns `true` if invoked to test if a package in this module is exported to itself. It always returns `true` when invoked on an unnamed module. A package that is [open](../../java/lang/Module.html#isOpen%28java.lang.String,java.lang.Module%29) to the given module is considered exported to that module at run-time and so this method returns `true` if the package is open to the given module.
This method does not check if the given module reads this module.
Parameters:
`pn` \- The package name
`other` \- The other module
Returns:
`true` if this module exports the package to at least the given module
See Also:
[ModuleDescriptor.exports()](../../java/lang/module/ModuleDescriptor.html#exports%28%29), [addExports(String,Module)](../../java/lang/Module.html#addExports%28java.lang.String,java.lang.Module%29)
* #### isOpen
public boolean isOpen([String](../../java/lang/String.html "class in java.lang") pn,
[Module](../../java/lang/Module.html "class in java.lang") other)
Returns `true` if this module has _opened_ a package to at least the given module.
This method returns `true` if invoked to test if a package in this module is open to itself. It returns `true` when invoked on an[open](../../java/lang/module/ModuleDescriptor.html#isOpen%28%29) module with a package in the module. It always returns `true` when invoked on an unnamed module.
This method does not check if the given module reads this module.
Parameters:
`pn` \- The package name
`other` \- The other module
Returns:
`true` if this module has _opened_ the package to at least the given module
See Also:
[ModuleDescriptor.opens()](../../java/lang/module/ModuleDescriptor.html#opens%28%29), [addOpens(String,Module)](../../java/lang/Module.html#addOpens%28java.lang.String,java.lang.Module%29), `AccessibleObject#setAccessible(boolean)`, [MethodHandles.privateLookupIn(java.lang.Class<?>, java.lang.invoke.MethodHandles.Lookup)](../../java/lang/invoke/MethodHandles.html#privateLookupIn%28java.lang.Class,java.lang.invoke.MethodHandles.Lookup%29)
* #### isExported
public boolean isExported([String](../../java/lang/String.html "class in java.lang") pn)
Returns `true` if this module exports the given package unconditionally.
This method always returns `true` when invoked on an unnamed module. A package that is [opened](../../java/lang/Module.html#isOpen%28java.lang.String%29) unconditionally is considered exported unconditionally at run-time and so this method returns `true` if the package is opened unconditionally.
This method does not check if the given module reads this module.
Parameters:
`pn` \- The package name
Returns:
`true` if this module exports the package unconditionally
See Also:
[ModuleDescriptor.exports()](../../java/lang/module/ModuleDescriptor.html#exports%28%29)
* #### isOpen
public boolean isOpen([String](../../java/lang/String.html "class in java.lang") pn)
Returns `true` if this module has _opened_ a package unconditionally.
This method always returns `true` when invoked on an unnamed module. Additionally, it always returns `true` when invoked on an[open](../../java/lang/module/ModuleDescriptor.html#isOpen%28%29) module with a package in the module.
This method does not check if the given module reads this module.
Parameters:
`pn` \- The package name
Returns:
`true` if this module has _opened_ the package unconditionally
See Also:
[ModuleDescriptor.opens()](../../java/lang/module/ModuleDescriptor.html#opens%28%29)
* #### addExports
public [Module](../../java/lang/Module.html "class in java.lang") addExports([String](../../java/lang/String.html "class in java.lang") pn,
[Module](../../java/lang/Module.html "class in java.lang") other)
If the caller's module is this module then update this module to export the given package to the given module.
This method has no effect if the package is already exported (or_open_) to the given module.
API Note:
As specified in section 5.4.3 of the The Java™ Virtual Machine Specification , if an attempt to resolve a symbolic reference fails because of a linkage error, then subsequent attempts to resolve the reference always fail with the same error that was thrown as a result of the initial resolution attempt.
Parameters:
`pn` \- The package name
`other` \- The module
Returns:
this module
Throws:
`[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- If `pn` is `null`, or this is a named module and the package `pn` is not a package in this module
`[IllegalCallerException](../../java/lang/IllegalCallerException.html "class in java.lang")` \- If this is a named module and the caller's module is not this module
See Also:
[isExported(String,Module)](../../java/lang/Module.html#isExported%28java.lang.String,java.lang.Module%29)
See The Java™ Virtual Machine Specification:
5.4.3 Resolution
* #### addOpens
public [Module](../../java/lang/Module.html "class in java.lang") addOpens([String](../../java/lang/String.html "class in java.lang") pn,
[Module](../../java/lang/Module.html "class in java.lang") other)
If this module has _opened_ a package to at least the caller module then update this module to open the package to the given module. Opening a package with this method allows all types in the package, and all their members, not just public types and their public members, to be reflected on by the given module when using APIs that support private access or a way to bypass or suppress default Java language access control checks.
This method has no effect if the package is already _open_ to the given module.
API Note:
This method can be used for cases where a _consumer module_ uses a qualified opens to open a package to an _API module_ but where the reflective access to the members of classes in the consumer module is delegated to code in another module. Code in the API module can use this method to open the package in the consumer module to the other module.
Parameters:
`pn` \- The package name
`other` \- The module
Returns:
this module
Throws:
`[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- If `pn` is `null`, or this is a named module and the package `pn` is not a package in this module
`[IllegalCallerException](../../java/lang/IllegalCallerException.html "class in java.lang")` \- If this is a named module and this module has not opened the package to at least the caller's module
See Also:
[isOpen(String,Module)](../../java/lang/Module.html#isOpen%28java.lang.String,java.lang.Module%29), `AccessibleObject#setAccessible(boolean)`, [MethodHandles.privateLookupIn(java.lang.Class<?>, java.lang.invoke.MethodHandles.Lookup)](../../java/lang/invoke/MethodHandles.html#privateLookupIn%28java.lang.Class,java.lang.invoke.MethodHandles.Lookup%29)
* #### addUses
public [Module](../../java/lang/Module.html "class in java.lang") addUses([Class](../../java/lang/Class.html "class in java.lang")<?> service)
If the caller's module is this module then update this module to add a service dependence on the given service type. This method is intended for use by frameworks that invoke [ServiceLoader](../../java/util/ServiceLoader.html "class in java.util") on behalf of other modules or where the framework is passed a reference to the service type by other code. This method is a no-op when invoked on an unnamed module or an automatic module.
This method does not cause [resolveAndBind](../../java/lang/module/Configuration.html#resolveAndBind%28java.lang.module.ModuleFinder,java.lang.module.ModuleFinder,java.util.Collection%29) to be re-run.
Parameters:
`service` \- The service type
Returns:
this module
Throws:
`[IllegalCallerException](../../java/lang/IllegalCallerException.html "class in java.lang")` \- If this is a named module and the caller's module is not this module
See Also:
[canUse(Class)](../../java/lang/Module.html#canUse%28java.lang.Class%29), [ModuleDescriptor.uses()](../../java/lang/module/ModuleDescriptor.html#uses%28%29)
* #### canUse
public boolean canUse([Class](../../java/lang/Class.html "class in java.lang")<?> service)
Indicates if this module has a service dependence on the given service type. This method always returns `true` when invoked on an unnamed module or an automatic module.
Parameters:
`service` \- The service type
Returns:
`true` if this module uses service type `st`
See Also:
[addUses(Class)](../../java/lang/Module.html#addUses%28java.lang.Class%29)
* #### getPackages
public [Set](../../java/util/Set.html "interface in java.util")<[String](../../java/lang/String.html "class in java.lang")> getPackages()
Returns the set of package names for the packages in this module.
For named modules, the returned set contains an element for each package in the module.
For unnamed modules, this method is the equivalent to invoking the[getDefinedPackages](../../java/lang/ClassLoader.html#getDefinedPackages%28%29) method of this module's class loader and returning the set of package names.
Returns:
the set of the package names of the packages in this module
* #### getAnnotation
public <T extends [Annotation](../../java/lang/annotation/Annotation.html "interface in java.lang.annotation")> T getAnnotation([Class](../../java/lang/Class.html "class in java.lang")<T> annotationClass)
Returns this element's annotation for the specified type if such an annotation is _present_, else null. This method returns `null` when invoked on an unnamed module.
Specified by:
`[getAnnotation](../../java/lang/reflect/AnnotatedElement.html#getAnnotation%28java.lang.Class%29)` in interface `[AnnotatedElement](../../java/lang/reflect/AnnotatedElement.html "interface in java.lang.reflect")`
Type Parameters:
`T` \- the type of the annotation to query for and return if present
Parameters:
`annotationClass` \- the Class object corresponding to the annotation type
Returns:
this element's annotation for the specified annotation type if present on this element, else null
* #### getAnnotations
public [Annotation](../../java/lang/annotation/Annotation.html "interface in java.lang.annotation")[] getAnnotations()
Returns annotations that are _present_ on this element. If there are no annotations _present_ on this element, the return value is an array of length 0\. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers. This method returns an empty array when invoked on an unnamed module.
Specified by:
`[getAnnotations](../../java/lang/reflect/AnnotatedElement.html#getAnnotations%28%29)` in interface `[AnnotatedElement](../../java/lang/reflect/AnnotatedElement.html "interface in java.lang.reflect")`
Returns:
annotations present on this element
* #### getDeclaredAnnotations
public [Annotation](../../java/lang/annotation/Annotation.html "interface in java.lang.annotation")[] getDeclaredAnnotations()
Returns annotations that are _directly present_ on this element. This method ignores inherited annotations. If there are no annotations _directly present_ on this element, the return value is an array of length 0\. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers. This method returns an empty array when invoked on an unnamed module.
Specified by:
`[getDeclaredAnnotations](../../java/lang/reflect/AnnotatedElement.html#getDeclaredAnnotations%28%29)` in interface `[AnnotatedElement](../../java/lang/reflect/AnnotatedElement.html "interface in java.lang.reflect")`
Returns:
annotations directly present on this element
* #### getResourceAsStream
public [InputStream](../../java/io/InputStream.html "class in java.io") getResourceAsStream([String](../../java/lang/String.html "class in java.lang") name)
throws [IOException](../../java/io/IOException.html "class in java.io")
Returns an input stream for reading a resource in this module. The `name` parameter is a `'/'`\-separated path name that identifies the resource. As with [Class.getResourceAsStream](../../java/lang/Class.html#getResourceAsStream%28java.lang.String%29), this method delegates to the module's class loader [findResource(String,String)](../../java/lang/ClassLoader.html#findResource%28java.lang.String,java.lang.String%29) method, invoking it with the module name (or `null` when the module is unnamed) and the name of the resource. If the resource name has a leading slash then it is dropped before delegation.
A resource in a named module may be _encapsulated_ so that it cannot be located by code in other modules. Whether a resource can be located or not is determined as follows:
* If the resource name ends with "`.class`" then it is not encapsulated.
* A _package name_ is derived from the resource name. If the package name is a [package](../../java/lang/Module.html#getPackages%28%29) in the module then the resource can only be located by the caller of this method when the package is [open](../../java/lang/Module.html#isOpen%28java.lang.String,java.lang.Module%29) to at least the caller's module. If the resource is not in a package in the module then the resource is not encapsulated.
In the above, the _package name_ for a resource is derived from the subsequence of characters that precedes the last `'/'` in the name and then replacing each `'/'` character in the subsequence with `'.'`. A leading slash is ignored when deriving the package name. As an example, the package name derived for a resource named "`a/b/c/foo.properties`" is "`a.b.c`". A resource name with the name "`META-INF/MANIFEST.MF`" is never encapsulated because "`META-INF`" is not a legal package name.
This method returns `null` if the resource is not in this module, the resource is encapsulated and cannot be located by the caller, or access to the resource is denied by the security manager.
Parameters:
`name` \- The resource name
Returns:
An input stream for reading the resource or `null`
Throws:
`[IOException](../../java/io/IOException.html "class in java.io")` \- If an I/O error occurs
See Also:
[Class.getResourceAsStream(String)](../../java/lang/Class.html#getResourceAsStream%28java.lang.String%29)
* #### toString
public [String](../../java/lang/String.html "class in java.lang") toString()
Returns the string representation of this module. For a named module, the representation is the string `"module"`, followed by a space, and then the module name. For an unnamed module, the representation is the string `"unnamed module"`, followed by a space, and then an implementation specific string that identifies the unnamed module.
Overrides:
`[toString](../../java/lang/Object.html#toString%28%29)` in class `[Object](../../java/lang/Object.html "class in java.lang")`
Returns:
The string representation of this module