scala/scala.github.com — Issue #39: Pattern matching in Scala for Java programmers tutorial
Author: santiagobasulto
Created: 2012-02-04 15:26:17+00:00
State: open

Hello friends,

i'm finishing the translation of this tutorial: https://github.com/scala/scala.github.com/blob/gh-pages/tutorials/scala-for-java-programmers.md

When discussing traits, the authors define this method:

override def equals(that: Any): Boolean = that.isInstanceOf[Date] && {
val o = that.asInstanceOf[Date]
o.day == day && o.month == month && o.year == year
}

Shouldn't be better to define the same method this way:

override def equals(that: Any): Boolean = that match{
case o:Date => o.day == day && o.month == month && o.year == year
case _ => return false
}

Maybe a note can be added noting the type erasure problem.

What do you think?