Skip to content

Instantly share code, notes, and snippets.

@ponkotuy
Last active August 29, 2015 13:56
Show Gist options
  • Save ponkotuy/9225301 to your computer and use it in GitHub Desktop.
Save ponkotuy/9225301 to your computer and use it in GitHub Desktop.
補助コンストラクタでなぜかcompileできないパターン
object Main extends App {
val hoge = new Hoge()
println((hoge.hoge, hoge.fuga))
}
class Hoge(val hoge: Int, val fuga: Int) {
import Hoge._
def this() = this(init, init) // Compile Erorr! not found init
}
object Hoge {
val init = 1
}
object Main extends App {
val hoge = new Hoge()
println((hoge.hoge, hoge.fuga))
}
class Hoge(val hoge: Int, val fuga: Int) {
def this() = {
import Hoge._ // Compile Error! this expected but import found
this(init, init)
}
}
object Hoge {
val init = 1
}
@gakuzzzz
Copy link

あれ、嘘つきましたね。 this 先に呼び出せば処理かけますね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment