Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一堂课
class MyClass(a: Int, b: String) { //.... }
如果我想向这个构造函数添加一些自定义逻辑(代码),我该怎么做?
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") }