?? testerasure.java
字號(hào):
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
class Apple<T extends Number>
{
T size;
public Apple()
{
}
public Apple(T size)
{
this.size = size;
}
public void setA(T size)
{
this.size = size;
}
public T getSize()
{
return this.size;
}
}
public class TestErasure
{
public static void main(String[] args)
{
Apple<Integer> a = new Apple<Integer>(6);
//a的getSize方法返回Integer對(duì)象
Integer as = a.getSize();
//把a(bǔ)對(duì)象賦給Apple變量,會(huì)丟失尖括號(hào)里的類型信息
Apple b = a;
//b只知道size的類型是Number
Number size1 = b.getSize();
//下面代碼引起編譯錯(cuò)誤
//Integer size2 = b.getSize();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -