I find I occasionally want to write an arbitrary assertion in a trait, or in some other place where the thing I want to make an assertion on is not yet fully defined.
trait Foo {
val aList: List[String]
val anotherList: List[String]
def printPairs = aList.zip(anotherList).foreach(println)
assert(aList.size == anotherList.size) // NullPointerException, because these references are undefined right now.
}
I suppose a generalization of what I'm looking for is a hook that (always) fires after the class is fully defined and instantiated, since this is the sort of check I'd generally put in a constructor.