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>
泛型解决的是向下转型所带来的安全隐患,其核心的组成就是在声明类<>
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<>();
}
}
“?”可以接收任意的泛型类型,只能够取出,但是不能修改。