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 the
Package
is compatible with a particular specification version
by using the Package.
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 is
sealed.
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:
package-info.class
as specified above.
A Package
automatically defined for classes in an unnamed module
has the following properties:
""
(for classes in an unnamed package)
or derived from the binary names of the classes
(for classes in a named package).package-info.class
as specified above.
A Package
can be obtained with the Package.
and ClassLoader.
methods.
Every Package
defined by a class loader can be obtained
with the Package.
and
ClassLoader#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.
ClassLoader#definePackage(String, String, String, String, String, String, String, URL)
Modifier and Type | Class and Description |
---|---|
pack-priv static class |
Modifier and Type | Field and Description |
---|---|
private Class | |
private final Package. |
Access | Constructor and Description |
---|---|
pack-priv | Package(String
the name of the package name, String the title of the specification spectitle, String the version of the specification specversion, String the organization that maintains the specification specvendor, String the title of the implementation impltitle, String the version of the implementation implversion, String the organization that maintains the implementation implvendor, URL code source where this Package comes from sealbase, ClassLoader defining class loader loader)Construct a package instance for an unnamed module with the specified version information. |
pack-priv |
Modifier and Type | Method and Description |
---|---|
public <A extends Annotation> A | getAnnotation(Class<A>
the Class object corresponding to the
annotation type annotationClass)Implements java. Returns this element's annotation for the specified type if such an annotation is present, else null. |
public Annotation[] | getAnnotations()
Implements java. Returns annotations that are present on this element. |
public <A extends Annotation> A[] | getAnnotationsByType(Class<A>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. Returns annotations that are associated with this element. |
public <A extends Annotation> A | getDeclaredAnnotation(Class<A>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. Returns this element's annotation for the specified type if such an annotation is directly present, else null. |
public Annotation[] | getDeclaredAnnotations()
Implements java. Returns annotations that are directly present on this element. |
public <A extends Annotation> A[] | getDeclaredAnnotationsByType(Class<A>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present. |
public String | Returns: the title of the implementation,null is returned if it is not known.Return the title of this package. |
public String | Returns: the vendor that implemented this package,null
is returned if it is not known.Returns the vendor that implemented this package, |
public String | Returns: the version of the implementation,null is returned if it is not known.Return the version of this implementation. |
public String | |
public static Package | Returns: ThePackage of the given name defined by the caller's
class loader or its ancestors, or null if not found.A package name, such as " name)java.lang ".
Deprecated
since 9. If multiple class loaders delegate to each other and define classes
with the same package name, and one such loader relies on the lookup
behavior of
getPackage to return a Package from
a parent loader, then the properties exposed by the Package
may not be as expected in the rest of the program.
Finds a package by name in the caller's class loader and its ancestors. |
private Class | |
public static Package[] | Returns: The array ofPackage objects defined by this
class loader and its ancestorsReturns all of the |
public String | Returns: the specification title,null is returned if it is not known.Return the title of the specification that this package implements. |
public String | Returns: the specification vendor,null is returned if it is not known.Return the name of the organization, vendor, or company that owns and maintains the specification of the classes that implement this package. |
public String | Returns: the specification version,null is returned if it is not known.Returns the version number of the specification that this package implements. |
public int | Returns: the hash code computed from the package name.Overrides java. Return the hash code computed from the package name. |
public boolean | isAnnotationPresent(Class<? extends Annotation>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. Returns true if an annotation for the specified type is present on this element, else false. |
public boolean | Returns: true if this package's version number is greater than or equal to the desired version numberthe version string of the desired version. desired)Compare this package's specification version with a desired version. |
public boolean | Returns: true if the package is sealed, false otherwiseReturns true if this package is sealed. |
public boolean | |
public String | Returns: the string representation of the package.Overrides java. Returns the string representation of this Package. |
packageInfo | back to summary |
---|---|
private Class<?> packageInfo |
versionInfo | back to summary |
---|---|
private final Package. |
Package | back to summary |
---|---|
pack-priv Package(String name, String spectitle, String specversion, String specvendor, String impltitle, String implversion, String implvendor, URL sealbase, ClassLoader loader) Construct a package instance for an unnamed module with the specified version information. API Note This method should not be called to define a Package for named module.
|
Package | back to summary |
---|---|
pack-priv Package(String name, Module module) |
getAnnotation | back to summary |
---|---|
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) Implements java. Doc from java. Returns this element's annotation for the specified type if such an annotation is present, else null. Note that any annotation returned by this method is a declaration annotation.
|
getAnnotations | back to summary |
---|---|
public Annotation[] getAnnotations() Implements java. Doc from java. 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. Note that any annotations returned by this method are declaration annotations.
|
getAnnotationsByType | back to summary |
---|---|
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) Overrides default java. Doc from java. Returns annotations that are associated with this element.
If there are no annotations associated with this element, the return
value is an array of length 0.
The difference between this method and Note that any annotations returned by this method are declaration annotations.
|
getDeclaredAnnotation | back to summary |
---|---|
public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) Overrides default java. Doc from java. Returns this element's annotation for the specified type if such an annotation is directly present, else null. This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.) Note that any annotation returned by this method is a declaration annotation.
|
getDeclaredAnnotations | back to summary |
---|---|
public Annotation[] getDeclaredAnnotations() Implements java. Doc from java. 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. Note that any annotations returned by this method are declaration annotations.
|
getDeclaredAnnotationsByType | back to summary |
---|---|
public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) Overrides default java. Doc from java. Returns this element's annotation(s) for the specified type if
such annotations are either directly present or
indirectly present. This method ignores inherited
annotations.
If there are no specified annotations directly or indirectly
present on this element, the return value is an array of length
0.
The difference between this method and
|
getImplementationTitle | back to summary |
---|---|
public String getImplementationTitle() Return the title of this package.
|
getImplementationVendor | back to summary |
---|---|
public String getImplementationVendor() Returns the vendor that implemented this package,
|
getImplementationVersion | back to summary |
---|---|
public String getImplementationVersion() Return the version of this implementation. It consists of any string assigned by the vendor of this implementation and does not have any particular syntax specified or expected by the Java runtime. It may be compared for equality with other package version strings used for this implementation by this vendor for this package.
|
getName | back to summary |
---|---|
public String getName() Return the name of this package. |
getPackage | back to summary |
---|---|
public static Package getPackage(String name)
Deprecated since 9. If multiple class loaders delegate to each other and define classes
with the same package name, and one such loader relies on the lookup
behavior of Finds a package by name in the caller's class loader and its ancestors.
If the caller's class loader defines a
Calling this method is equivalent to calling
|
getPackageInfo | back to summary |
---|---|
private Class |
getPackages | back to summary |
---|---|
public static Package[] getPackages() Returns all of the
Calling this method is equivalent to calling
|
getSpecificationTitle | back to summary |
---|---|
public String getSpecificationTitle() Return the title of the specification that this package implements.
|
getSpecificationVendor | back to summary |
---|---|
public String getSpecificationVendor() Return the name of the organization, vendor, or company that owns and maintains the specification of the classes that implement this package.
|
getSpecificationVersion | back to summary |
---|---|
public String getSpecificationVersion() Returns the version number of the specification that this package implements. This version string must be a sequence of non-negative decimal integers separated by "."'s and may have leading zeros. When version strings are compared the most significant numbers are compared. Specification version numbers use a syntax that consists of non-negative decimal integers separated by periods ".", for example "2.0" or "1.2.3.4.5.6.7". This allows an extensible number to be used to represent major, minor, micro, etc. versions. The version specification is described by the following formal grammar:
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Return the hash code computed from the package name.
|
isAnnotationPresent | back to summary |
---|---|
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) Overrides default java. Doc from java. Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations. The truth value returned by this method is equivalent to:
|
isCompatibleWith | back to summary |
---|---|
public boolean isCompatibleWith(String desired) throws NumberFormatException Compare this package's specification version with a desired version. It returns true if this packages specification version number is greater than or equal to the desired version number. Version numbers are compared by sequentially comparing corresponding components of the desired and specification strings. Each component is converted as a decimal integer and the values compared. If the specification value is greater than the desired value true is returned. If the value is less false is returned. If the values are equal the period is skipped and the next pair of components is compared.
|
isSealed | back to summary |
---|---|
public boolean isSealed() Returns true if this package is sealed. API Note Package sealing
has no relationship with sealed classes or interfaces.
Package sealing is specific to JAR files defined for classes in an unnamed module.
See the
|
isSealed | back to summary |
---|---|
public boolean isSealed(URL url) Returns true if this package is sealed with respect to the specified
code source API Note Package sealing
has no relationship with sealed classes or interfaces.
Package sealing is specific to JAR files defined for classes in an unnamed module.
See the
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns the string representation of this Package. Its value is the string "package " and the package name. If the package title is defined it is appended. If the package version is defined it is appended. |
Modifier and Type | Field and Description |
---|---|
private final String | |
private final String | |
private final String | |
pack-priv static final Package. | |
private final URL | |
private final String | |
private final String | |
private final String |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
pack-priv static Package. |
implTitle | back to summary |
---|---|
private final String implTitle |
implVendor | back to summary |
---|---|
private final String implVendor |
implVersion | back to summary |
---|---|
private final String implVersion |
NULL_VERSION_INFO | back to summary |
---|---|
pack-priv static final Package. |
sealBase | back to summary |
---|---|
private final URL sealBase |
specTitle | back to summary |
---|---|
private final String specTitle |
specVendor | back to summary |
---|---|
private final String specVendor |
specVersion | back to summary |
---|---|
private final String specVersion |
VersionInfo | back to summary |
---|---|
private VersionInfo(String spectitle, String specversion, String specvendor, String impltitle, String implversion, String implvendor, URL sealbase) |
getInstance | back to summary |
---|---|
pack-priv static Package. |