Suppose I have a class
class MyClass(a: Int, b: String) {
//....
}
If I want to add some custom logic (code) to this constructor, how do I do that?
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With