타입이 호환될 수 있는 경우가 여러 가지 있을 수 있다. 이때 가장 구체적인 타입이 선택된다. 예
를 들어 암시적 인자의 타입이
Foo
라면, 범위 안에 들어 있는
Foo
타입의 암시적 값이
AnyRef
타입의 암시적 값보다 우선적으로 선택된다.
둘 이상의 암시적 값이 모호하다면(예를 들어 구체적인 타입이 같기 때문에) 컴파일러 오류가
발생한다.
컴파일러는 항상 일부 라이브러리 암시를 범위에 넣는 반면, 다른 라이브러리 암시는 반드시
임포트해야 사용할 수 있다. 이제 이런 암시에 대해 살펴보자.
5.7
스칼라가 기본 제공하는 암시
스칼라
2
.
11
라이브러리의 소스 코드에는
300
개 이상의 암시 메서드, 값, 타입이 들어 있다.
그중 대부분은 메서드며, 그런 메서드 중 대부분은 한 타입을 다른 타입으로 변환하기 위해 사
용된다. 어떤 암시가 여러분 코드에 영향을 끼칠지 아는 것이 중요하다. 따라서 여기서는 암시적
값을 그룹별로 나눠서 논한다. 모든 자세한 사항을 아는 것은 전혀 중요하지 않다. 하지만 어떤
암시가 존재하는지에 대해 ‘감’을 잡는 것은 도움이 될 것이다. 따라서 이번 절은 대강 살펴봐도
된다.
컬렉션의
CanBuildFrom
타입에 대해서는 이미 살펴봤다. 이와 비슷한
CanCombineFrom
타입은
이름이 암시하는 대로 인스턴스를 ...
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.