?? apple.java
字號:
import java.util.*;
/**
* 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
*/
//定義Apple類時使用了泛型聲明
public class Apple<T>
{
//使用T類型形參定義屬性
private T info;
public Apple(){}
//下面方法中使用T類型形參來定義方法
public Apple(T info)
{
this.info = info;
}
public void setInfo(T info)
{
this.info = info;
}
public T getInfo()
{
return this.info;
}
public static void main(String[] args)
{
//因為傳給T形參的是String實際類型,所以構造器的參數只能是String
Apple<String> a1 = new Apple<String>("蘋果");
System.out.println(a1.getInfo());
//因為傳給T形參的是Double實際類型,所以構造器的參數只能是Double或者double
Apple<Double> a2 = new Apple<Double>(5.67);
System.out.println(a2.getInfo());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -