스칼라의 객체지향 프로그래밍 구현에 대해 많은 것을 배웠다. 이 장에서는 표준 라이브러리의
타입 계층구조에 대해 자세히 다루고,
Predef
(
http
://
bit
.
ly
/
1086O2z
) 등의 타입을 깊이 살펴
볼 것이다.
하지만 우선 타입시스템에서 중요한 상속에 따른 변성
variance
이라는 특징을 논의하자. 이에 대해
알아야 이 장 뒷부분에서 다룰 라이브러리에 있는 여러 가지 타입을 이해할 수 있다.
그 후 객체의 동등성에 대해 논의하면서 이 장을 마칠 것이다.
10.1
매개변수화한 타입: 상속에 따른 변성
자바와 스칼라의 매개변수화한 타입(자바에서는 이를 보통 제네릭스라고 부른다)의 중요한 차
이점은 상속에 따른 변성을 다루느냐에 있다.
예를 들어 어떤 메서드가
List
[
AnyRef
]
타입의 인자를 취한다고 가정하자. 그렇다면 이 메서드
에
List
[
String
]
값을 넘길 수 있을까? 즉,
List
[
String
]
을
List
[
AnyRef
]
의 서브타입으로 간
주해야 할까? 그에 대한 답이 참인 종류의 변성을 공변성
covariant
이라고 한다. 컨테이너(매개변
수화한 타입)의 슈퍼타입
-
서브타입 관계가 타입 매개변수 사이의 관계와 ‘동일한 방향으로 진
행’하기 때문이다.
스칼라 객체 시스템
I
CHAPTER
10
420
2
부
기본기 다지기
또한 반공변성
contravariant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.