環境情報
Scalaバージョン:2.12.7
実行したソースコード
defClass.scala
class Example(val x:Int, val y:Int) {
def +(z: Int):Int {
this.x + this.y + z
}
}
object testExample extends App {
val e1: Example = new Example(1, 2)
println(e1 + 10)
}
発生したエラーメッセージ
error: illegal start of declaration (possible cause: missing `=' in front of current method body)
this.x + this.y + z
^
one error found
解決方法
「illegal start of declaration」にある通り、宣言の記述に問題がありました。
メソッドの宣言部分に = を記述すれば解決します。
def +(z: Int):Int {
を
def +(z: Int):Int = {
とすれば解決します。