views:

61

answers:

1

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

+5  A: 
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")

  // ...
}
Randall Schulz
Exactly what I was looking for
Jim