Created
February 14, 2014 08:27
-
-
Save anderssonfilip/8997607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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