This repository was archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollections_47.html
More file actions
163 lines (163 loc) · 7.84 KB
/
collections_47.html
File metadata and controls
163 lines (163 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 25 March 2009), see www.w3.org" />
<title>Scala 2.8 コレクション API -- Scala 2.7 からの移行</title>
<link rel="stylesheet" type="text/css" href="guide.css" />
</head>
<body dir="ltr">
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_48.html"><img border="0"
alt="謝辞" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_0.html"><img border="0"
alt="トップ" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_46.html"><img border="0"
alt="Java と Scala 間のコレクションの変換" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%"><b>Scala 2.7
からの移行</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
<blockquote style=
"border-left: 1px solid gray; font-family: Century, Times, 'Times New Roman', 'MS Gothic', serif; padding-left: 1em;">
最新版は <a href="http://docs.scala-lang.org/ja/overviews/collections/migrating-from-scala-27.html">Scala Documentation</a> に移行しました。
</blockquote>
<h1>Scala 2.7 からの移行</h1>
<p>既存の Scala
アプリケーションの新しいコレクションへの移植はほぼ自動的であるはずだ。問題となり得ることはいくつかしかない。</p>
<p>一般的論として、Scala 2.7
コレクションの古い機能はそのまま残っているはずだ。機能の中には廃止予定となったものもあり、それは今後のリリースで撤廃されるということだ。Scala
2.8 でそのような機能を使ったコードをコンパイルすると<em>廃止予定警告</em>
(deprecation warning) が発生する。その意味や性能特性を変えて 2.8
に残った演算もあり、その場合は廃止予定にするのは無理だった。このような場合は 2.8
でコンパイルすると<em>移行警告</em>
(migration warning) が出される。コードをどう変えればいいのかも提案してくれる完全な廃止予定警告と移行警告を得るには、<tt>-deprecation</tt>
と <tt>-Xmigration</tt> フラグを <tt>scalac</tt> に渡す
(<tt>-Xmigration</tt> は <tt>X</tt> で始まるため、拡張オプションであることに注意)。同じオプションを
<tt>scala</tt> REPL に渡すことで対話セッション上で警告を得ることができる。具体例としては:</p>
<div class="quote">
<table cellspacing="1" cellpadding="0">
<tr>
<td colspan="99" align="left">
<tt>>scala -deprecation -<font color=
"#660099">Xmigration</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">Welcome to Scala version 2.8.0.final</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">Type in expressions to have them evaluated.</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">Type :help for more information.</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#0000E5">val</font> xs = <font color=
"#660099">List</font>((<font color=
"#000000">1</font>, <font color=
"#000000">2</font>), (<font color=
"#000000">3</font>, <font color="#000000">4</font>))</tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">xs: List[(Int, Int)] = List((1,2), (3,4))</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left">
<tt>scala> List.unzip(xs)</tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"><console>:7: warning: method unzip in object List is deprecated: use xs.unzip instead of List.unzip(xs)</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> List.unzip(xs)</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> ^</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res0: (List[Int], List[Int]) = (List(1, 3),List(2, 4))</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> xs.unzip</tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res1: (List[Int], List[Int]) = (List(1, 3),List(2, 4))</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#0000E5">val</font> m = xs.toMap</tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">m: scala.collection.immutable.</font></tt><tt><font color="#590000">Map[Int,Int] = Map((1,2), (3,4))</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> m.keys</tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"><console>:8: warning: method keys in trait MapLike has changed semantics:</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">As of 2.8, keys returns Iterable[A] rather than Iterator[A].</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> m.keys</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> ^</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res2: Iterable[Int] = Set(1, 3)</font></tt></td>
</tr>
</table>
</div>
<p>旧ライブラリより完全に置き換えられ、廃止予定警告を出すのが無理だったものが 2つある。</p>
<ol>
<li>以前の <tt>scala.collection.jcl</tt> パッケージは撤廃された。 このパッケージは Scala
上で Java コレクションライブラリの設計を真似しようとしたが、それは多くの対称性を壊してしまった。Java
コレクションが欲しい人の多くは <tt>jcl</tt> を飛ばして <tt>java.util</tt>
を直接使用していた。Scala 2.8 は、<tt>jcl</tt> パッケージの代わりに、<a href=
"collections_46.html"><tt>JavaConversions</tt>
オブジェクト</a>にて両方のライブラリ間の自動変換機構を提供する。</li>
<li>投射 (projection)
は一般化され、きれいにされ、現在はビューとして提供される。投射はほとんど使われていなかったようなので、この変更に影響を受けるコードは少ないはずだ。</li>
</ol>
<p>よって、<tt>jcl</tt> か投射を使っている場合は多少コードの書き換えが必要になるかもしれない。</p>
<p>続いては、<a href="collections_48.html">謝辞</a></p>
<hr />
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_48.html"><img border="0"
alt="謝辞" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_0.html"><img border="0"
alt="トップ" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_46.html"><img border="0"
alt="Java と Scala 間のコレクションの変換" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%"><b>Scala 2.7
からの移行</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
</body>
</html>