사용자 도구

사이트 도구


java:generics

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판 양쪽 다음 판
java:generics [2018/10/19 15:23]
kwon37xi [현재 객체의 Generic Type 파라미터 클래스 알아내기]
java:generics [2018/10/19 15:23]
kwon37xi [현재 객체의 Generic Type 파라미터 클래스 알아내기]
줄 13: 줄 13:
  
 ===== 현재 객체의 Generic Type 파라미터 클래스 알아내기 ===== ===== 현재 객체의 Generic Type 파라미터 클래스 알아내기 =====
-  * 원칙적으로는 파라미터로 온 객체의 제너릭 타입을 알아낼 수 는 없다. 하지만 클래스가 제너릭일 경우 클래스 자신의 타입은 알아낼 수 있다.+  * Type erasure 때문에 원칙적으로는 파라미터로 온 객체의 제너릭 타입을 알아낼 수 는 없다. 하지만 클래스가 제너릭일 경우 클래스 자신의 타입은 알아낼 수 있다.
  
 >> Nope, that is not possible. Due to downwards compatibility issues, Java's generics are based on [[https://docs.oracle.com/javase/tutorial/java/generics/erasure.html|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 [[https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Field.html#getGenericType()|"what generic type does this field's definition use?"]]), not in object instances. >> Nope, that is not possible. Due to downwards compatibility issues, Java's generics are based on [[https://docs.oracle.com/javase/tutorial/java/generics/erasure.html|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 [[https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Field.html#getGenericType()|"what generic type does this field's definition use?"]]), not in object instances.
java/generics.txt · 마지막으로 수정됨: 2020/09/18 21:41 저자 kwon37xi