목차

Java Generics

Type Erasure

Java Generic은 컴파일 타임에만 타입 체킹용으로 사용되고, 실행시간에는 모두 Genric이 삭제된 상태로 동작한다. 컴파일러는 필요할 경우 타입 캐스팅 코드를 넣어서 컴파일 한다.

현재 객체의 Generic Type 파라미터 클래스 알아내기

Nope, that is not possible. Due to downwards compatibility issues, Java's generics are based on type erasure, i.a. at runtime, all you have is a non-generic List object. There is some information about type parameters at runtime, but it resides in class definitions (i.e. you can ask "what generic type does this field's definition use?"), not in object instances.
Type[] classes = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();

참조