?? applesandorangeswithoutgenerics.java
字號:
package chapter11;
import java.util.*;
class Apple{
private static long counter;
private final long id=counter++;
public long id(){
return id;
}
}
public class ApplesAndOrangesWithoutGenerics {
public static void main(String args[]){
ArrayList<Apple> apples=new ArrayList<Apple>();
/*
* 通過這種預定義的方式,可以指定這個容器實例保存的類型
*/
for(int i=0;i<3;i++){
apples.add(new Apple());
}
for(int i=0;i<apples.size();i++){
System.out.println((apples.get(i)).id());
/*
* 因此在這里,就不需要進行類型轉換了1
*/
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -