문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:generics [2013/08/28 15:34] kwon37xi [현재 객체의 Generic Type 파라미터 클래스 알아내기] |
java:generics [2018/10/19 15:23] kwon37xi [현재 객체의 Generic Type 파라미터 클래스 알아내기] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Java Generics ====== | ====== Java Generics ====== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
줄 11: | 줄 13: | ||
===== 현재 객체의 Generic Type 파라미터 클래스 알아내기 ===== | ===== 현재 객체의 Generic Type 파라미터 클래스 알아내기 ===== | ||
- | 아래의 결과는 Class 들의 배열이므로 원하는 순서의 것을 빼서 사용하면 된다. | + | * Type erasure 때문에 원칙적으로는 파라미터로 온 객체의 제너릭 타입을 알아낼 수 는 없다. 하지만 클래스가 제너릭일 경우 클래스 자신의 타입은 알아낼 수 있다. |
+ | |||
+ | >> Nope, that is not possible. Due to downwards compatibility issues, Java's generics are based on [[https:// | ||
+ | |||
+ | * 아래의 결과는 Class 들의 배열이므로 원하는 순서의 것을 빼서 사용하면 된다. | ||
<code java> | <code java> | ||
Type[] classes = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments(); | Type[] classes = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments(); | ||
</ | </ | ||
+ | * [[https:// | ||
+ | * [[https:// | ||