public class 软件包 extends Object implements AnnotatedElement
软件包
对象包含关于一个java包的实施和规范的版本信息。这个版本的信息检索和加载类的实例提供
ClassLoader
(ES)。通常情况下,它存储在分发的类中的清单中。
组成包的类可以实现一个特定的规范,如果是这样的规范标题,版本号和供应商字符串确定规范。应用程序可以问包是与一个特定的版本兼容,请参阅isCompatibleWith
方法。
规范的版本号使用的语法,包括非负十进制整数的时期“分离。”,例如“2”或“1.2.3.4.5.6.7”。这允许一个可扩展的数字来表示主要的,次要的,微型的,等版本。版本规范是由下面的形式语法描述的:
- SpecificationVersion:
- Digits RefinedVersionopt
- RefinedVersion:
.
Digits.
Digits RefinedVersion- Digits:
- Digit
- Digits
- Digit:
- any character for which
Character.isDigit(char)
returnstrue
, e.g. 0, 1, 2, ...
该实现的标题、版本和供应商字符串标识实现,并可方便地在发生问题时能够准确地报告所涉及的包的情况。所有三个实现字符串的内容都是特定于供应商的。实现版本字符串没有指定的语法,应该只与所需版本标识符的相等性进行比较。
每个ClassLoader
实例内从同一个java包中的所有类具有相同的封装对象。静态方法允许通过名称或已知的当前类装载器的所有包的集合被发现的包被发现。
Modifier and Type | Method and Description |
---|---|
<A extends Annotation> |
getAnnotation(类<A> annotationClass)
如果存在此注释,则返回此元素的指定类型的注释,否则为空。
|
Annotation[] |
getAnnotations()
返回此元素上的注释。
|
<A extends Annotation> |
getAnnotationsByType(类<A> annotationClass)
返回与此元素关联的注释。
|
<A extends Annotation> |
getDeclaredAnnotation(类<A> annotationClass)
返回此元素的指定类型的注释,如果这样的注释是直接存在的,否则为空。
|
Annotation[] |
getDeclaredAnnotations()
返回直接在该元素上的注释。
|
<A extends Annotation> |
getDeclaredAnnotationsByType(类<A> annotationClass)
如果这样的注释直接存在或间接存在,则返回指定类型的该元素的注释(s)。
|
String |
getImplementationTitle()
返回此包的标题。
|
String |
getImplementationVendor()
返回提供此实现的组织、供应商或公司的名称。
|
String |
getImplementationVersion()
返回此实现的版本。
|
String |
getName()
返回此包的名称。
|
static 软件包 |
getPackage(String name)
找到一个包的名字在电话
ClassLoader 实例。
|
static 软件包[] |
getPackages()
把所有的包,目前已知的呼叫者的
ClassLoader 实例。
|
String |
getSpecificationTitle()
返回此包实现的规范的标题。
|
String |
getSpecificationVendor()
返回拥有并维护实现此包的类的规范的组织、供应商或公司的名称。
|
String |
getSpecificationVersion()
返回此包实现的规范的版本号。
|
int |
hashCode()
返回从包名计算的哈希代码。
|
boolean |
isAnnotationPresent(类<? extends Annotation> annotationClass)
如果在这个元素上存在指定类型的注释,则返回真,否则为假。
|
boolean |
isCompatibleWith(String desired)
将此软件包的规范版本与所需版本进行比较。
|
boolean |
isSealed()
如果此包被密封,则返回真。
|
boolean |
isSealed(URL url)
如果此包相对于指定的代码源的地址密封,则返回真。
|
String |
toString()
返回此包的字符串表示形式。
|
public String getName()
java.lang
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
-源代码的URL
public boolean isCompatibleWith(String desired) throws NumberFormatException
版本号进行比较,通过顺序比较所需的和规范的字符串的相应组件。每个组件被转换为一个十进制整数和值比较。如果规格值大于所需的值,则返回。如果值小于假返回。如果值是相等的期间被跳过,和下一对组件进行比较。
desired
-所需的版本字符串。
NumberFormatException
-如果期望或当前版本不正确的虚线形式。
public static 软件包 getPackage(String name)
ClassLoader
实例。来电者
ClassLoader
实例对应的类的实例中找到包。如果用户
ClassLoader
实例为空则由系统
ClassLoader
实例加载包集查找指定的包。
只有当类装入器用适当的属性创建了包实例时,包才有版本和规范的属性。通常情况下,这些属性被定义在伴随类的清单中。
name
-包的名称,例如,一个。
public static 软件包[] getPackages()
ClassLoader
实例。这些包对应的加载通过或按名访问,
ClassLoader
实例类。如果来电者的
ClassLoader
实例引导
ClassLoader
实例,这可以通过在一些实现
null
表示,只有包对应的引导
ClassLoader
实例加载的类将返回。
ClassLoader
实例数组。一个零长度数组返回,如果没有人知道。
public int hashCode()
hashCode
方法重写,继承类
Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
public <A extends Annotation> A getAnnotation(类<A> annotationClass)
AnnotatedElement
getAnnotation
接口
AnnotatedElement
A
-查询并返回如果目前的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public boolean isAnnotationPresent(类<? extends Annotation> annotationClass)
此方法返回的真实价值相当于:getAnnotation(annotationClass) != null
默认方法的主体被指定为上面的代码。
isAnnotationPresent
接口
AnnotatedElement
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public <A extends Annotation> A[] getAnnotationsByType(类<A> annotationClass)
AnnotatedElement
AnnotatedElement.getAnnotation(Class)
之间的区别是,该方法检测如果它的参数是一个可重复的注释类型(年9.6),如果是这样的话,试图找到一个或更多的注释,通过“浏览”式容器标注。此方法的调用方可以自由修改返回的数组;它将对返回给其他调用方的数组没有影响。
getAnnotationsByType
接口
AnnotatedElement
A
-查询并返回如果目前的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public Annotation[] getAnnotations()
AnnotatedElement
getAnnotations
接口
AnnotatedElement
public <A extends Annotation> A getDeclaredAnnotation(类<A> annotationClass)
AnnotatedElement
getDeclaredAnnotation
接口
AnnotatedElement
A
-查询,如果直接提出返回的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public <A extends Annotation> A[] getDeclaredAnnotationsByType(类<A> annotationClass)
AnnotatedElement
AnnotatedElement.getDeclaredAnnotation(Class)
之间的区别是,该方法检测如果它的参数是一个可重复的注释类型(年9.6),如果是这样的话,试图找到一个或更多的注释,通过“浏览”式容器注释如果存在。此方法的调用方可以自由修改返回的数组;它将对返回给其他调用方的数组没有影响。
getDeclaredAnnotationsByType
接口
AnnotatedElement
A
-注释类型来查询并返回如果直接或间接存在
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public Annotation[] getDeclaredAnnotations()
AnnotatedElement
getDeclaredAnnotations
接口
AnnotatedElement
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.