Is there any particular reason why Regex.MatchData.group(i: Int): java.lang.String returns null rather than Option[String]?
Is there a "Scala Way" to handle nulls in Scala?
Is there any particular reason why Regex.MatchData.group(i: Int): java.lang.String returns null rather than Option[String]?
Is there a "Scala Way" to handle nulls in Scala?
It returns null because it is a shallow interface over the Java library. I think it sucks too, and I have been bitten by it.
If you get a value that may be null, you can write
Option(value)
on Scala 2.8 and it will become eitherNone
orSome(value)
. That doesn't work with pattern matching, but you can write your own extractor for that:Examples: