java.lang
public class Package extends Object implements AnnotatedElement
The most useful method is the isCompatibleWith()
method that
compares a desired version of a specification with the version of the
specification as implemented by a package. A package is considered
compatible with another version if the version of the specification is
equal or higher then the requested version. Version numbers are represented
as strings of positive numbers separated by dots (e.g. "1.2.0").
The first number is called the major number, the second the minor,
the third the micro, etc. A version is considered higher then another
version if it has a bigger major number then the another version or when
the major numbers of the versions are equal if it has a bigger minor number
then the other version, etc. (If a version has no minor, micro, etc numbers
then they are considered the be 0.)
Modifier and Type | Method and Description |
---|---|
<A extends Annotation> |
getAnnotation(Class<A> annotationClass)
Returns this package's annotation for the specified annotation type,
or
null if no such annotation exists. |
Annotation[] |
getAnnotations()
Returns all annotations associated with this package.
|
Annotation[] |
getDeclaredAnnotations()
Returns all annotations directly defined by this package.
|
String |
getImplementationTitle()
Returns the name of the implementation, or null if unknown.
|
String |
getImplementationVendor()
Returns the vendor that wrote this implementation, or null if unknown.
|
String |
getImplementationVersion()
Returns the version of this implementation, or null if unknown.
|
String |
getName()
Returns the Package name in dot-notation.
|
static Package |
getPackage(String name)
Returns the named package if it is known by the callers class loader.
|
static Package[] |
getPackages()
Returns all the packages that are known to the callers class loader.
|
String |
getSpecificationTitle()
Returns the name of the specification, or null if unknown.
|
String |
getSpecificationVendor()
Returns the name of the specification designer, or null if unknown.
|
String |
getSpecificationVersion()
Returns the version of the specification, or null if unknown.
|
int |
hashCode()
Returns the hashCode of the name of this package.
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type is associated
with this package.
|
boolean |
isCompatibleWith(String version)
Checks if the version of the specification is higher or at least as high
as the desired version.
|
boolean |
isSealed()
Returns true if this Package is sealed.
|
boolean |
isSealed(URL url)
Returns true if this Package is sealed and the origin of the classes is
the given URL.
|
String |
toString()
Returns a string representation of this package.
|
public String getName()
public String getSpecificationTitle()
public String getSpecificationVersion()
public String getSpecificationVendor()
public String getImplementationTitle()
public String getImplementationVersion()
public String getImplementationVendor()
public boolean isSealed()
public boolean isSealed(URL url)
url
- the URL to testNullPointerException
- if url is nullpublic boolean isCompatibleWith(String version)
getSpecificationVersion
.version
- the (minimal) desired version of the specificationNumberFormatException
- if either version string is invalidNullPointerException
- if either version string is nullpublic static Package getPackage(String name)
name
- the name of the desired packagepublic static Package[] getPackages()
public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public String toString()
"package " + getName() + (getSpecificationTitle() == null
? "" : ", " + getSpecificationTitle()) + (getSpecificationVersion()
== null ? "" : ", version " + getSpecificationVersion())
.toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
null
if no such annotation exists.getAnnotation
in interface AnnotatedElement
annotationClass
- the type of annotation to look for.null
if no such annotation exists.public Annotation[] getAnnotations()
getAnnotations
in interface AnnotatedElement
public Annotation[] getDeclaredAnnotations()
getDeclaredAnnotations
in interface AnnotatedElement
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
isAnnotationPresent
in interface AnnotatedElement
annotationClass
- the type of annotation to look for.