0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Scala]illegal start of declarationエラーの対処法

Last updated at Posted at 2018-11-25

環境情報

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 = {

とすれば解決します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?