Package (Java SE 15 & JDK 15) (original) (raw)

All Implemented Interfaces:

[AnnotatedElement](reflect/AnnotatedElement.html "interface in java.lang.reflect")


public class Package extends Object implements AnnotatedElement

Represents metadata about a run-time package associated with a class loader. Metadata includes annotations, versioning, and sealing.

Annotations for the run-time package are read from package-info.class at the same code source as classes in the run-time package.

The set of classes that make up the run-time package may implement a particular specification. The specification title, version, and vendor (indicating the owner/maintainer of the specification) can be provided when the Package is defined. An application can ask if thePackage is compatible with a particular specification version by using the Package.isCompatibleWith(String) method. In addition, information about the actual classes that make up the run-time package can be provided when the Package is defined. This information consists of an implementation title, version, and vendor (indicating the supplier of the classes).

A Package may be explicitly defined with the ClassLoader.definePackage(String, String, String, String, String, String, String, URL) method. The caller supplies the specification and implementation titles, versions, and vendors. The caller also indicates whether the package issealed. If a Package is not explicitly defined for a run-time package when a class in that run-time package is defined, then a Package is automatically defined by the class's defining class loader, as follows.

A Package automatically defined for classes in a named module has the following properties:

A Package automatically defined for classes in an unnamed module has the following properties:

A Package can be obtained with the Package.getPackage(String) and ClassLoader.getDefinedPackage(String) methods. Every Package defined by a class loader can be obtained with the Package.getPackages() andClassLoader.getDefinedPackages() methods.

Implementation Note:

The builtin class loaders do not explicitly define Package objects for packages in_named modules_. Instead those packages are automatically defined and have no specification and implementation versioning information.

See Java Virtual Machine Specification:

5.3 Creation and Loading

Since:

1.2

See Also:

The JAR File Specification: Package Sealing, ClassLoader.definePackage(String, String, String, String, String, String, String, URL)

Modifier and Type Method Description
<A extends Annotation>A getAnnotation​(Class annotationClass) Returns this element's annotation for the specified type if such an annotation is present, else null.
Annotation[] getAnnotations() Returns annotations that are present on this element.
<A extends Annotation>A[] getAnnotationsByType​(Class annotationClass) Returns annotations that are associated with this element.
<A extends Annotation>A getDeclaredAnnotation​(Class annotationClass) Returns this element's annotation for the specified type if such an annotation is directly present, else null.
Annotation[] getDeclaredAnnotations() Returns annotations that are directly present on this element.
<A extends Annotation>A[] getDeclaredAnnotationsByType​(Class annotationClass) Returns this element's annotation(s) for the specified type if such annotations are either directly present or_indirectly present_.
String getImplementationTitle() Return the title of this package.
String getImplementationVendor() Returns the vendor that implemented this package, null is returned if it is not known.
String getImplementationVersion() Return the version of this implementation.
String getName() Return the name of this package.
static Package getPackage​(String name) Deprecated.
static Package[] getPackages() Returns all of the Packages defined by the caller's class loader and its ancestors.
String getSpecificationTitle() Return the title of the specification that this package implements.
String getSpecificationVendor() Return the name of the organization, vendor, or company that owns and maintains the specification of the classes that implement this package.
String getSpecificationVersion() Returns the version number of the specification that this package implements.
int hashCode() Return the hash code computed from the package name.
boolean isAnnotationPresent​(Class<? extends Annotation> annotationClass) Returns true if an annotation for the specified type is present on this element, else false.
boolean isCompatibleWith​(String desired) Compare this package's specification version with a desired version.
boolean isSealed() Returns true if this package is sealed.
boolean isSealed​(URL url) Returns true if this package is sealed with respect to the specified code source url.
String toString() Returns the string representation of this Package.