⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 50820c5a2275001d1dddb6604daa6ad2

📁 java程序设计教程的源码
💻
字号:
//【例5-23】  限制泛型与通配符泛型的应用示例。
//程序清单5-23:  CollectionGenFoo.java
package Generics.wildcard;
import java.util.*;
public class CollectionGenFoo<T extends Collection> {
	private T x;
	public static void main(String args[]) {
		CollectionGenFoo<ArrayList> listFoo1 = null;
		listFoo1 = new CollectionGenFoo<ArrayList>(new ArrayList());
		// 由于没有使用通配符泛型,下面两句编译时出错
		// CollectionGenFoo<Collection> listFoo2 = null;
		// listFoo2 = new CollectionGenFoo<ArrayList>(new ArrayList());
		// 以下使用了通配符泛型
		CollectionGenFoo<? extends Collection> listFoo3 = null;
		listFoo3 = new CollectionGenFoo<LinkedList>(new LinkedList());
		System.out.println("实例化成功!");
	}
	public CollectionGenFoo(T x) {this.x = x;	}
	public T getX() {	return x;}
	public void setX(T x) {	this.x = x;}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -