Skip to content

Commit 5ecdcbd

Browse files
committed
null match added
1 parent ea2dd33 commit 5ecdcbd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

solutions/src/main/scala/org/scalalabs/basic/lab03/PatternMatchingExercise.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ object PatternMatchingExercise {
3737
def matchOnInputType(in: Any) = in match {
3838
case s: String => s"A string with length ${s.length}"
3939
case i: Int if i > 0 => "A positive integer"
40-
case Person(name, _) => s"A person with name: $name"
40+
case p @ Person(_,_) => s"A person with name: ${p.name}"
4141
case s: Seq[_] if (s.size > 10) => "Seq with more than 10 elements"
4242
case first :: second :: tail => s"first: $first, second: $second, rest: $tail"
4343
case o: Option[_] => "A Scala Option subtype"
4444
case a: AnyRef => "Some Scala class"
45-
case _ => "A null value"
45+
case null => "A null value"
46+
case _ => "The default"
4647
}
4748

4849
def older(p: Person): Option[String] = p match {

0 commit comments

Comments
 (0)