?Generic
Note that type parameters can represent only reference types, not primitive types (like int, double and char).
只能是引用類型,不能是基本類型
范型的通配符問題
The type parameters can be used to declare the return type and act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments.
<?>
//有約束的通配
<? extends List>
<? super ArrayList>
泛型解決的是向下轉(zhuǎn)型所帶來的安全隱患坯约,其核心的組成就是在聲明類<>
public class WildCard<T> {
? ? private T foo;
? ? public T getFoo() {return foo;}
? ? public void setFoo(T foo) {this.foo = foo;}
? ? public static void main(String[] args) {
? ? ? ? WildCard<?> ge1 = new WildCard<>();
? ? ? ? WildCard<String> ge2 = new WildCard<>();
? ? }
}
“?”可以接收任意的泛型類型耽梅,只能夠取出拉岁,但是不能修改寂恬。