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

📄 arrayofgenerics10.java

📁 Thinking In Java 第四版练习题答案
💻 JAVA
字号:
// arrays/ArrayOfGenerics10.java
// TIJ4 Chapter Arrays, Exercise 10, page 762
// Modify ArrayOfGeneric.java to use containers instead of arrays.
// Show that you can eliminate the compile-time warnings.
import java.util.*;

public class ArrayOfGenerics10 {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		List<List<String>> lls = new ArrayList<List<String>>();
		List<List> l = new ArrayList<List>();	
		// lls = (List<List<String>>)l; // error: inconvertible types
		lls.add(new ArrayList<String>());
		List<Object> lo = new ArrayList<Object>();
		// lo = lls; // error: incompatible types
		// Compile-time warning eliminated:
		List<List<BerylliumSphere>> llb = 
			new ArrayList<List<BerylliumSphere>>();
		for(int i = 0; i < 10; i++) {
			llb.add(new ArrayList<BerylliumSphere>());
				for(int j = 0; j < 2; j++)
					llb.get(i).add(new BerylliumSphere());
		}
		System.out.println(llb);	
	}
}

⌨️ 快捷键说明

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