Skip to content

Commit b289e62

Browse files
committed
Move 'View' page to 'Implicit-conversions' and applied updated version Korean translation to it.
1 parent f61faed commit b289e62

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
layout: tutorial
3+
title: 암시적 변환
4+
5+
disqus: true
6+
7+
tutorial: scala-tour
8+
num: 26
9+
language: ko
10+
---
11+
12+
타입 `S`로부터 타입 `T`로의 암시적 변환는 함수 타입 `S => T`의 암시적 값이나 해당 타입으로 변환 가능한 암시적 메소드로 정의된다.
13+
14+
암시적 변환은 두 가지 상황에 적용된다.
15+
16+
* 표현식 `e`의 타입이 `S`이고, `S`는 표현식의 기대 타입 `T`를 따르지 않을 때.
17+
* `e`의 타입이 `T``e.m`를 선택한 상황에서, 선택자 `m``T`의 멤버가 아닐 때.
18+
19+
20+
첫 번째 경우에서 변환 `c``e`에 적용되며, 결과 타입이 `T`를 따르는지 탐색한다.
21+
두 번째 경우에선 변환 `c``e`에 적용되며, 결과가 `m`이라는 이름의 멤버를 포함하고 있는지 탐색한다.
22+
23+
타입이 `List[Int]`인 두 리스트 xs와 ys의 아래 연산은 허용된다:
24+
25+
xs <= ys
26+
27+
아래에 정의된 암시적 메소드 `list2ordered``int2ordered`가 범위 안에 있다고 가정한다.
28+
29+
implicit def list2ordered[A](x: List[A])
30+
(implicit elem2ordered: a => Ordered[A]): Ordered[List[A]] =
31+
new Ordered[List[A]] { /* .. */ }
32+
33+
implicit def int2ordered(x: Int): Ordered[Int] =
34+
new Ordered[Int] { /* .. */ }
35+
36+
암시적으로 임포트되는 오브젝트 `scala.Predef`는 미리 정의된 여러 타입(예: `Pair`)과 메소드(예: `assert`)뿐만 아니라 여러 뷰도 함께 선언한다.
37+
38+
예를들면, `java.lang.Integer`를 기대하는 자바 메서드를 호출할때, `scala.Int`를 대신 넘겨도 무방하다. 그 이유는 Predef가 아래 암시적 변환들을 포함하기 때문이다.
39+
40+
```tut
41+
import scala.language.implicitConversions
42+
43+
implicit def int2Integer(x: Int) =
44+
java.lang.Integer.valueOf(x)
45+
```
46+
47+
암시적 변환이 무분별하게 사용될 경우 잠재적인 위험을 가질 수 있기 때문에, 컴파일러는 암시적 변환의 선언을 컴파일할때 경고한다.
48+
49+
To turn off the warnings take either of these actions:
50+
경고를 끄기 위해서는 아래 중 하나를 선택해야 한다.
51+
52+
* `scala.language.implicitConversions` 를 암시적 변환의 선언이 있는 범위로 import
53+
* `-language:implicitConversions` 옵션으로 컴파일러 실행
54+
55+
변환이 컴팡일러에 의해 적용될때 경고가 발생하지 않는다.
56+
57+
58+
윤창석, 이한욱 옮김, 고광현 업데이트

ko/tutorials/tour/unified-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: tutorial
3-
title: 통합 타입
3+
title: 통합된 타입
44

55
disqus: true
66

ko/tutorials/tour/views.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)