File tree 3 files changed +13
-3
lines changed
getting-started/intellij-track
3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Scala には複数のライブラリとテスト方法がありますが、こ
16
16
1 . ScalaTest への依存を追加します。
17
17
1 . ` build.sbt ` ファイルに ScalaTest への依存を追加します。
18
18
```
19
- libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5 " % "test"
19
+ libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8 " % "test"
20
20
```
21
21
1. `build.sbt was changed` という通知が出たら、**auto-import** を選択します。
22
22
1. これらの2つのアクションにより、`sbt` が ScalaTest ライブラリをダウンロードします。
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ class Stack[A] {
35
35
手続き` def push ` は型` A ` のオブジェクトのみを受け取ります
36
36
(注: ` elements = x :: elements ` は、` x ` を現在の` elements ` の先頭に追加した新しいリストを` elements ` に割り当て直します)。
37
37
38
+ ここで ` Nil ` は空の ` List ` であり、 ` null ` と混同してはいけません。
39
+
38
40
## 使い方
39
41
40
42
ジェネリッククラスを使うには、角カッコの中に` A ` の代わりに型を入れます。
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ language: ja
33
33
` main ` と呼ばれるメソッドがあり、それはパラメータとしてコマンドライン引数(文字列の配列)を受け取ります。
34
34
このメソッドの本体は、事前に定義されたメソッド ` println ` に友好的な挨拶を引数にして、1回だけ呼び出しています。
35
35
` main ` メソッドは値を返しません(手続きメソッド)。
36
- そのため、戻り値の型を宣言する必要はありません 。
36
+ そのため、その戻り値の型は ` Unit ` として宣言されます 。
37
37
38
38
Java プログラマにあまりなじみがないのは、` main ` メソッドを含む ` object ` という宣言です。
39
39
Scala はそのような宣言によって、一般に** シングルトンオブジェクト** として知られる、インスタンスを1つだけ有するクラスを取り入れています。
@@ -259,9 +259,17 @@ Scalaでは、スーパークラスから継承されたメソッドをオーバ
259
259
def re = real
260
260
def im = imaginary
261
261
override def toString() =
262
- "" + re + (if (im < 0) "- " else "+ ") + im + "i"
262
+ "" + re + (if (im >= 0) "+ " else "") + im + "i"
263
263
}
264
264
265
+ オーバーライドされた ` toString ` は以下のように呼び出せます。
266
+
267
+ object ComplexNumbers {
268
+ def main(args: Array[String]): Unit = {
269
+ val c = new Complex(1.2, 3.4)
270
+ println("Overridden toString(): " + c.toString)
271
+ }
272
+ }
265
273
266
274
## ケースクラスとパターンマッチ
267
275
You can’t perform that action at this time.
0 commit comments