4

クラスがあるとします

  class MyClass(a: Int, b: String) {
   //....
  }

このコンストラクターにカスタム ロジック (コード) を追加したい場合、どうすればよいですか?

4

1 に答える 1

17
class MyClass(a: Int, b: String) {
   // this is the constructor right here
   println("Hi, i'm the constructor")

   def imAMethod = 1

   println("Hi, I'm also part of the constructor down here, the whole class body is")
}
于 2013-06-04T03:45:20.130 に答える