scala怎么定義無參構造函數
2 回答

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
直接寫到類的里面就可以了:
scala> class A {
| //do anything you want
| println("Hi, the construtor invoked here..")
| }
defined class A
scala> val a = new A
Hi, the construtor invoked here..
a: A = A@1339a0dc
scala>
上面的Scala代碼基本等價于下面的Java代碼:
public class A {
public A() {
//do anything you want
println("Hi, the construtor invoked here..");
}
}
- 2 回答
- 0 關注
- 858 瀏覽
添加回答
舉報
0/150
提交
取消