- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
who likes writing def equals?
Wed, 2009-11-04, 23:10
Nobody! What if some sort of leprechaun could write your equals and
hashCode methods and all you had to do was pay them a little manifest?
// notice only x passed to superclass as value equality basis
class Measurement[T: Manifest](x: Int, y: Int) extends util.EqualsHelperClass[T](x)
class Velocity
class Distance
class SuperVelocity extends Velocity
val x1 = new Measurement[Velocity](5, 0)
val x2 = new Measurement[Distance](5, 0)
val x3 = new Measurement[SuperVelocity](5, 0)
val x4 = new Measurement[Velocity](5, 5150)
x1 != x2 // not same type
x1 != x3 // nope, subtypes do not confuse us
x1 == x4 // winner
Or skip the values:
scala> EqualsHelper[List[List[Int]]] == EqualsHelper[List[List[String]]]
res7: Boolean = false
scala> EqualsHelper[List[List[Int]]] == EqualsHelper[List[List[Int]]]
res8: Boolean = true
I'm not checking it in though because my excitement limit has been
exceeded for a while. If anyone wants to look it over and anticipate
issues, branch and source file are at:
http://github.com/paulp/scala/tree/equalsHelper
http://tinyurl.com/y98dymu
On Wed, Nov 4, 2009 at 8:10 PM, Paul Phillips <paulp@improving.org> wrote:
--
Daniel C. Sobral
Veni, vidi, veterni.