by shigemk2

当面は技術的なことしか書かない

Scalaの諸エラー

type mismatch

指定した型と右辺が異なればエラー。

scala> val a: Int = "string"
<console>:7: error: type mismatch;
 found   : String("string")
 required: Int
       val a: Int = "string"
                    ^

刺激を求める技術者に捧げるScala講座 - 第2回 Scalaの基本的な文法:ITpro

illegal start of declaration

(主にメソッドまわりで)宣言をミスるとエラー。

scala> def add(x: Int, y:Int): Int {
     | x + y
<console>:2: error: illegal start of declaration (possible cause: missing `=' in front of current method body)
       x + y
       ^

Why illegal start of declaration in Scala? - Stack Overflow