Skip to content

Instantly share code, notes, and snippets.

@anderssonfilip
Created February 14, 2014 08:27
Show Gist options
  • Save anderssonfilip/8997607 to your computer and use it in GitHub Desktop.
Save anderssonfilip/8997607 to your computer and use it in GitHub Desktop.
class PairOfShoes(var leftSize: Int, var rightSize: Int) {
def mix(newLeftSize: Int, newRightSize: Int) =
{
leftSize = newLeftSize
rightSize = newRightSize
}
override def hashCode(): Int = leftSize + 31 * rightSize
def canEqual(that: Any): Boolean = that match {
case p: PairOfShoes => true
case _ => false
}
override def equals(that: Any): Boolean = {
def strictEquals(that: PairOfShoes) =
{
this.leftSize == that.leftSize && this.rightSize == that.rightSize
}
that match {
case a: AnyRef if this eq a => true
case p: PairOfShoes => (p canEqual this) && strictEquals(p)
case _ => false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment