泛型的使用:類、接口、方法~

/**

 * 泛型類
 * 
 * @author Administrator
 *
 * @param <T>
 */
public class MyGeneric<T> {
private T value;


public T getValue() {
return value;
}


public void setValue(T value) {
this.value = value;
}


}

/**
 * 泛型接口
 * 
 * @author Administrator
 *
 * @param <T>
 * @param <U>
 */
public interface Show<T, U> {
void show(T t, U u);
}

/**
 * 泛型方法
 * 
 * @author Administrator
 *
 */
public class GenericMethod {
public static void main(String[] args) throws ClassNotFoundException {
String str = get("Hello", "World");
System.out.println(str);
}


public static <T, U> T get(T t, U u) {
if (u != null)
return t;
else
return null;
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章