public class Package extends Object implements AnnotatedElement
Packages are managed by class loaders. All classes loaded by the same loader
from the same package share a Package
instance.
ClassLoader
Modifier and Type | Method and Description |
---|---|
<A extends Annotation> |
getAnnotation(Class<A> annotationType)
Gets the annotation associated with the specified annotation type and
this package, if present.
|
Annotation[] |
getAnnotations()
Returns an empty array.
|
Annotation[] |
getDeclaredAnnotations()
Returns an empty array.
|
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()
Indicates whether this package is sealed.
|
boolean |
isSealed(URL url)
Indicates whether this package is sealed with respect to the specified
URL.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
public <A extends Annotation> A getAnnotation(Class<A> annotationType)
getAnnotation
in interface AnnotatedElement
annotationType
- the annotation type to look for.Annotation
or null
.AnnotatedElement.getAnnotation(java.lang.Class)
public Annotation[] getAnnotations()
getAnnotations
in interface AnnotatedElement
public Annotation[] getDeclaredAnnotations()
getDeclaredAnnotations
in interface AnnotatedElement
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
isAnnotationPresent
in interface AnnotatedElement
annotationType
- the annotation type to look for.true
if the annotation is present; false
otherwise.AnnotatedElement.isAnnotationPresent(java.lang.Class)
public String getImplementationTitle()
null
if this is unknown. The format of this string is unspecified.null
.public String getImplementationVendor()
null
if this is unknown. The
format of this string is unspecified.null
.public String getImplementationVersion()
null
if this is unknown. The format of this string is unspecified.null
.public String getName()
public static Package getPackage(String packageName)
null
is returned.packageName
- the name of the package to find.null
.ClassLoader.getPackage(java.lang.String)
public static Package[] getPackages()
ClassLoader.getPackages()
public String getSpecificationTitle()
null
if this is unknown.null
.public String getSpecificationVendor()
null
if this is
unknown.null
.public String getSpecificationVersion()
null
if this is unknown. The version string is a sequence of
non-negative integers separated by dots; for example: "1.2.3".null
.public int hashCode()
Object
Object.equals(java.lang.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.
hashCode
in class Object
Object.equals(java.lang.Object)
public boolean isCompatibleWith(String version) throws NumberFormatException
version
- the version string to compare against.true
if the package versions are compatible; false
otherwise.NumberFormatException
- if this package's version string or the one provided are not
in the correct format.public boolean isSealed()
true
if this package is sealed; false
otherwise.public boolean isSealed(URL url)
url
- the URL to check.true
if this package is sealed with url
; false
otherwisepublic String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.