Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Package

public class Package
extends Object implements AnnotatedElement

java.lang.Object
   ↳ java.lang.Package


Contains information about a Java package. This includes implementation and specification versions. Typically this information is retrieved from the manifest.

Packages are managed by class loaders. All classes loaded by the same loader from the same package share a Package instance.

See also:

Summary

Public methods

<A extends Annotation> A getAnnotation(Class<A> annotationType)

Returns the annotation associated with the specified annotation type and this package, if present.

Annotation[] getAnnotations()

Returns an array of this package's annotations.

Annotation[] getDeclaredAnnotations()

Returns an array of this package's declared annotations.

String getImplementationTitle()

Returns the title of the implementation of this package, or null if this is unknown.

String getImplementationVendor()

Returns the name of the vendor or organization that provides this implementation of the package, or null if this is unknown.

String getImplementationVersion()

Returns the version of the implementation of this package, or null if this is unknown.

String getName()

Returns the name of this package in the standard dot notation; for example: "java.lang".

static Package getPackage(String packageName)

Attempts to locate the requested package in the caller's class loader.

static Package[] getPackages()

Returns all the packages known to the caller's class loader.

String getSpecificationTitle()

Returns the title of the specification this package implements, or null if this is unknown.

String getSpecificationVendor()

Returns the name of the vendor or organization that owns and maintains the specification this package implements, or null if this is unknown.

String getSpecificationVersion()

Returns the version of the specification this package implements, or null if this is unknown.

int hashCode()

Returns an integer hash code for this object.

boolean isAnnotationPresent(Class<? extends Annotation> annotationType)

Indicates whether the specified annotation is present.

boolean isCompatibleWith(String version)

Indicates whether this package's specification version is compatible with the specified version string.

boolean isSealed(URL url)

Indicates whether this package is sealed with respect to the specified URL.

boolean isSealed()

Indicates whether this package is sealed.

String toString()

Returns a string containing a concise, human-readable description of this object.

Inherited methods

From class java.lang.Object
From interface java.lang.reflect.AnnotatedElement

Public methods

getAnnotation

Added in API level 9
A getAnnotation (Class<A> annotationType)

Returns the annotation associated with the specified annotation type and this package, if present.

Parameters
annotationType Class: the annotation type to look for.
Returns
A an instance of Annotation or null.

See also:

getAnnotations

Added in API level 1
Annotation[] getAnnotations ()

Returns an array of this package's annotations.

Returns
Annotation[] an array of all annotations for this element

getDeclaredAnnotations

Added in API level 1
Annotation[] getDeclaredAnnotations ()

Returns an array of this package's declared annotations. Package annotations aren't inherited, so this is equivalent to getAnnotations().

Returns
Annotation[] an array of annotations declared for this element

getImplementationTitle

Added in API level 1
String getImplementationTitle ()

Returns the title of the implementation of this package, or null if this is unknown. The format of this string is unspecified.

Returns
String the implementation title, may be null.

getImplementationVendor

Added in API level 1
String getImplementationVendor ()

Returns the name of the vendor or organization that provides this implementation of the package, or null if this is unknown. The format of this string is unspecified.

Returns
String the implementation vendor name, may be null.

getImplementationVersion

Added in API level 1
String getImplementationVersion ()

Returns the version of the implementation of this package, or null if this is unknown. The format of this string is unspecified.

Returns
String the implementation version, may be null.

getName

Added in API level 1
String getName ()

Returns the name of this package in the standard dot notation; for example: "java.lang".

Returns
String the name of this package.

getPackage

Added in API level 1
Package getPackage (String packageName)

Attempts to locate the requested package in the caller's class loader. If no package information can be located, null is returned.

Parameters
packageName String: the name of the package to find.
Returns
Package the requested package, or null.

See also:

getPackages

Added in API level 1
Package[] getPackages ()

Returns all the packages known to the caller's class loader.

Returns
Package[] all the packages known to the caller's class loader.

See also:

getSpecificationTitle

Added in API level 1
String getSpecificationTitle ()

Returns the title of the specification this package implements, or null if this is unknown.

Returns
String the specification title, may be null.

getSpecificationVendor

Added in API level 1
String getSpecificationVendor ()

Returns the name of the vendor or organization that owns and maintains the specification this package implements, or null if this is unknown.

Returns
String the specification vendor name, may be null.

getSpecificationVersion

Added in API level 1
String getSpecificationVersion ()

Returns the version of the specification this package implements, or null if this is unknown. The version string is a sequence of non-negative integers separated by dots; for example: "1.2.3".

Returns
String the specification version string, may be null.

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
int this object's hash code.

isAnnotationPresent

Added in API level 1
boolean isAnnotationPresent (Class<? extends Annotation> annotationType)

Indicates whether the specified annotation is present.

Parameters
annotationType Class: the annotation type to look for.
Returns
boolean true if the annotation is present; false otherwise.

See also:

isCompatibleWith

Added in API level 1
boolean isCompatibleWith (String version)

Indicates whether this package's specification version is compatible with the specified version string. Version strings are compared by comparing each dot separated part of the version as an integer.

Parameters
version String: the version string to compare against.
Returns
boolean true if the package versions are compatible; false otherwise.
Throws
NumberFormatException if this package's version string or the one provided are not in the correct format.

isSealed

Added in API level 1
boolean isSealed (URL url)

Indicates whether this package is sealed with respect to the specified URL.

Parameters
url URL: the URL to check.
Returns
boolean true if this package is sealed with url; false otherwise

isSealed

Added in API level 1
boolean isSealed ()

Indicates whether this package is sealed.

Returns
boolean true if this package is sealed; false otherwise.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.