In the pattern matching example, an empty case is required by default , because otherwise the match expression will raise a MatchError for each expr argument that is not a bar.
The fact that no code is specified for this second case, so if this case is executed, it does nothing.
The result of any of these is the value of Unit () , which is also the result of the entire expression of correspondence.
For more information, see Martin Odersky Programming with Scala in Class Classes and Pattern Matching.
source share