如果我们考虑任何泛型类型,例如,下面给出的代码取自java.util.Collections
,
static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
private static final long serialVersionUID = 1820017752578914078L;
final Collection<? extends E> c;
UnmodifiableCollection(Collection<? extends E> c) {
if (c==null)
throw new NullPointerException();
this.c = c;
}
public int size() {return c.size();}
public boolean isEmpty() {return c.isEmpty();}
public boolean contains(Object o) {return c.contains(o);}
public Object[] toArray() {return c.toArray();}
public <T> T[] toArray(T[] a) {return c.toArray(a);}
public String toString() {return c.toString();}
public Iterator<E> iterator() {
...
}
public boolean add(E e) {
throw new UnsupportedOperationException();
}
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
public boolean containsAll(Collection<?> coll) {
return c.containsAll(coll);
}
public boolean addAll(Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
public boolean removeAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
public boolean retainAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean removeIf(Predicate<? super E> filter) {
throw new UnsupportedOperationException();
}
}
我想明白,
1)
如何为上述代码识别TypeElement
包的ExecutableElement
,VariableElement
,AnnotationMirror
,javax.lang.model.element
个角色?
2)
如何为上述代码识别DeclaredType
包的WildcardType
,ExecutableType
,MirrorType
,javax.lang.model.type
个角色?
3)AnnotationMirror
是element
中提到的基于镜像的反射系统吗?
注意:type
&amp; Object.getClass()
包是元级别工具,与传统反射系统(Type.class
方法或FLT_MAX
文字)不同
答案 0 :(得分:0)
*Type
和AnnotationMirror
类都是javax.lang.model.element
包的一部分,在构建自定义注释处理器时使用它。这个基类是javax.annotation.processing.Processor
,这是一个开始寻求帮助的好地方。
基本上,所有这些类型都代表调用注释处理器的编译器的抽象语法树中的节点。它们是只读的,这意味着您只能添加自定义错误,但无法修改源代码。