I'd like to test the arguments to my case class constructor and throw an exception if they fail certain tests. The compiler complained when I tried to write my own apply method (Multiple 'apply' methods.
I suppose I could make it a non-case class, and do the apply/unapply constructor field stuff myself, but I had hoped not to.
Thanks
case class Picky(i: Int, s: String) {
require(i % 2 == 0, "i must be even")
require(s.length < 50, "s length must be less than 50 characters")
// ...
}
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