java泛型之通配符的使用。

来源:互联网 发布:软件生命周期概念 编辑:程序博客网 时间:2024/05/29 18:19

代码如下:

package test;
/** 
* @author : suyuyuan
* @date :2016年7月1日 下午3:13:41 
* @version 1.0 
*/
class Info<T>{
private T key;


public T getKey() {
return key;
}


public void setKey(T key) {
this.key = key;
}
@Override
public String toString() {
return this.getKey().toString();
}
}
public class GenTest {
public static void main(String[] args) {
Info<String> i = new Info<String>();
i.setKey("Hello World!");
tell(i);
}

public static void tell(Info<?> i){     // 此处使用了通配符    ?
System.out.println(i);
}
}



0 0
原创粉丝点击