public interface Element extends AnnotatedConstruct
元素应该使用equals(Object)
方法相比。没有任何保证,任何特定的元素将始终以同一对象表示。
实现基于一个Element
对象类的操作,或者使用一个visitor或使用的getKind()
方法的结果。使用instanceof
未必是一个可靠的成语确定该模型的层次对象的有效课堂,因为一个实现可以选择有一个单一的对象实现多个接口Element
。
Elements
,
TypeMirror
Modifier and Type | Method and Description |
---|---|
<R,P> R |
accept(ElementVisitor<R,P> v, P p)
将此元素应用到该元素。
|
TypeMirror |
asType()
返回由该元素定义的类型。
|
boolean |
equals(Object obj)
返回
true 如果参数是相同的元素,
this ,或
false 否则。
|
<A extends Annotation> |
getAnnotation(类<A> annotationType)
如果这样的诠释是返回指定类型的这种构造的诠释,其他
null 。
|
List<? extends AnnotationMirror> |
getAnnotationMirrors()
返回直接存在于此结构上的注释。
|
List<? extends Element> |
getEnclosedElements()
返回由该元素直接包含的元素,这个元素是松散的。
|
Element |
getEnclosingElement()
返回此元素的内部元素,松散地说,封闭的。
|
ElementKind |
getKind()
返回该元素的
kind 。
|
Set<Modifier> |
getModifiers()
返回此元素的改性剂,不包括注释。
|
Name |
getSimpleName()
返回此元素的简单(不合格)名称。
|
int |
hashCode()
遵循
Object.hashCode 一般合同。
|
getAnnotationsByType
TypeMirror asType()
一个通用元素定义了一个类型的家庭,而不仅仅是一个。如果这是一个通用的元素,一个原型类型返回。这是元素对对应于它自己的形式类型参数的类型变量的调用。例如,对于通用类元C<N extends Number>
,参数类型C<N>
返回。的Types
实用接口具有更一般的方法获取的元素中定义的类型的全方位。
Types
ElementKind getKind()
kind
。
Set<Modifier> getModifiers()
public
和
static
修饰符接口成员,包括。
Name getSimpleName()
java.util.Set<E>
简单的名字是
"Set"
。如果这个元素代表一位不愿透露姓名的
package,空叫回来。如果它是一个
constructor,命名为“
<init>
”返回。如果它是一个
static initializer,命名为“
<clinit>
”返回。如果它是一个
anonymous class或
instance initializer,空叫回来。
Element getEnclosingElement()
null
返回。null
如果没有
Elements.getPackageOf(javax.lang.model.element.Element)
List<? extends Element> getEnclosedElements()
请注意,某些种类的元素可以在ElementFilter
使用方法分离。
PackageElement.getEnclosedElements()
,
TypeElement.getEnclosedElements()
,
Elements.getAllMembers(javax.lang.model.element.TypeElement)
boolean equals(Object obj)
true
如果参数是相同的元素,
this
,或
false
否则。
请注意,元素的身份涉及到不直接访问该元素的方法的隐式状态,包括不相关的类型的存在状态。元对象通过这些接口的不同实现了应不可望平等即使“同”元素建模;这是类似于类
对象不为同一类文件通过不同的类加载器加载。
equals
方法重写,继承类
Object
obj
将这个元素比较的对象
true
指定对象是否表示相同的元素,这
Object.hashCode()
,
HashMap
int hashCode()
Object.hashCode
一般合同。
hashCode
方法重写,继承类
Object
equals(java.lang.Object)
List<? extends AnnotationMirror> getAnnotationMirrors()
要继承注释为好,使用getAllAnnotationMirrors
。
getAnnotationMirrors
接口
AnnotatedConstruct
<A extends Annotation> A getAnnotation(类<A> annotationType)
null
。
此方法返回的注释可以包含一个元素的值的类型是类
。这个值不能直接返回:查找和加载类的必要信息(如类装载器使用)不可用,并可能无法加载所有的类。试图读取一个类
对象通过调用返回的注释相关的方法将导致一个MirroredTypeException
,从中可提取出相应的TypeMirror
。同样,试图读一Class[]
-valued元素将导致MirroredTypesException
。
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.
getAnnotation
接口
AnnotatedConstruct
A
的注释类型
annotationType
-对应的注释类型的
类
对象
null
AnnotatedConstruct.getAnnotationMirrors()
,
AnnotatedElement.getAnnotation(java.lang.Class<T>)
,
EnumConstantNotPresentException
,
AnnotationTypeMismatchException
,
IncompleteAnnotationException
,
MirroredTypeException
,
MirroredTypesException
<R,P> R accept(ElementVisitor<R,P> v, P p)
R
-访问者的方法的返回类型
P
到访问者的方法的附加参数的类型
v
-访客在此元件的操作
p
附加参数
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.