Last Updated: February 25, 2016
·
531
· eugener

Method constraints in Scala

Method require allows definition of additional run-time constraints:

def post(tweet: String) = {
  require(tweet.length > 0, "message is too short")
  require(tweet.length < 140, "message is too long")
  println(tweet)
}