(25일차) 11월 29일
Class에서 Generic 표기법 : Class이름 + <영어대문자> ex) Box<T>
1. 영어대문자(data type 의미) : T, K, V 등으로 표현 (영문자 중 어떤 글자라도 사용 가능)
2. data type은 compile할 때 결정됨
- 예) Box<String>으로 사용하면 T는 compile시에 String으로 결정되고 Box<Apple>이면 T는 Apple로 결정되며
Box<Integer>이면 T는 Integer로 결정됨
3. 어떠한 class로 data type을 결정하더라고 casting 없이 사용 가능
4. Generic type인 T는 class뿐만 아니라, Interface도 사용 가능
method로 Generic 표기법
- <T> + 리턴타입 + 메소드명(매개변수)
ex) <T> Box<T> boxing(T t)
- <T> : 타입 파라미터 - 컴파일 시 구체적인 타입으로 변경 해줌
- Box<T> : 리턴타입
- boxing(T t) : 메소드명(매개변수)
Generic Wildcard type
1. <?> : 모든 class type이 허용
2. <? extends Student> : 최상위 부모인 Student와 자식을 포함한 후손 class들만 허용
3. <? super Worker> : Worker class와 Worker class의 부모와 조상 class들만 허용
실습문제6 풀이
프로젝트 Ch14_JavaAPI => 패키지 p11.arrays_method => 클래스 Member, SortEx : 완료 (※ 중요)
프로젝트 Ch14_JavaAPI => 패키지 p12.wrapper_class => 클래스 BoxingUnBoxingEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p12.wrapper_class => 클래스 AutoBoxingUnBoxingEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p12.wrapper_class => 클래스 StringToPrimitiveEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p12.wrapper_class => 클래스 ValueCompareEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p13.random_class => 클래스 RandomEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p14.date_calendar_calss => 클래스 DateEx : 완료
프로젝트 Ch14_JavaAPI => 패키지 p14.date_calendar_calss => 클래스 CalendarEx : 완료
프로젝트 Ch10_Inheritance => 패키지 p11.practice.polymorphism2 => 클래스 Tire, Car, HankookTire, KumhoTire, CarExample : 완료 (※ 헷갈림) 3:17 설명
프로젝트 Ch15_Generic => 패키지 p01.not_generic => 클래스 Box, Apple, BoxEx : 완료
프로젝트 Ch15_Generic => 패키지 p01.using_generic => 클래스 Box, Apple, BoxEx : 완료 (※ 중요)
프로젝트 Ch15_Generic => 패키지 p02.multi_type_generic => 클래스 Product, ProductEx : 완료
프로젝트 Ch15_Generic => 패키지 p03.generic_method => 클래스 Util, Box, GenericMethodEx : 완료 (※ 헷갈림)
프로젝트 Ch15_Generic => 패키지 p03.generic_method2 => 클래스 Util, Pair, GenericMethodEx : 완료 (※ 헷갈림)
프로젝트 Ch15_Generic => 패키지 p04.restricted_generic => 클래스 Course, RestrictedGenericEx, Person, Student, Worker, HighStudent : 완료 (※ 헷갈림)