如果我們考慮任何泛型類型,例如,從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
,javax.lang.model.type
包的MirrorType
角色上面的代碼?
3)AnnotationMirror
是一個基於鏡像的反射系統,如paper所述?
注:element
& type
包是元級的設施,這是從傳統的反射系統(Object.getClass()
方法或Type.class
字面)
這些與'UnmodifiableCollection'有什麼關係?你對這個類有特定的問題,或者你的問題是否適用於任何泛型? – Clashsoft
@Clashsoft我只是以此爲例。我的問題適用於任何泛型類型。我看到你部分回答了 – overexchange
夠公平的,我已經猜到了。 – Clashsoft