class Box<T> { … }Box<T> : 제네릭 클래스T : 타입 변수 또는 타입 매개 변수Box : 원시 타입제네릭 타입을 메서드 리턴 타입 앞에 선언한 메서드
public static <T> T getName(T name) { … }제네릭 메소드에서 사용되는 와 제네릭 타입으로 사용되는 T는 다르다.
public class Student<T> {
static <T> T getOneStudent(T id) {
return id;
}
}
Student<Long>.getOneStudent(17)
Student 클래스에서 사용되고 있는 T와 getOneStudent()에서 사용되고 있는 T는 전혀 다르다.static 메서드에서는 제네릭을 타입(타입 매개변수)을 사용할 수 없다.
public static void printAll(ArrayList<? extends Test> list1, ArrayList<extends Test> list2) { … }