陪伴而非守候
直接写到类的里面就可以了:scala> class A {| //do anything you want| println("Hi, the construtor invoked here..")| }defined class Ascala> val a = new AHi, the construtor invoked here..a: A = A@1339a0dcscala>上面的Scala代码基本等价于下面的Java代码:public class A {public A() {//do anything you wantprintln("Hi, the construtor invoked here..");}}