Is there a way to overload a constructor with more than just a one-line constructor? It seems like putting any more than one statement in an overloaded constructor gives the error Application does not take parameters
. For example, if the primary constructor take a String
, the following will work:
def this(num: Int) = {
this(num.toString())
}
The following, however, will not:
def this(num: Int) = {
val numAsString = num.toString()
this(numAsString)
}
You can rewrite as follows:
def this(num: Int) =
this{
val numAsString = num.toString
numAsString
}
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