假设我有一个班级
class MyClass(a: Int, b: String) {
//....
}
如果我想为这个构造函数添加一些自定义逻辑(代码),我该怎么做?
答案 0 :(得分:15)
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")
}