« Return to Thread: equals in case class does not seem to be working...

Re: equals in case class does not seem to be working...

by Paul Phillips-3 :: Rate this Message:

Reply to Author | View in Thread

On Wed, Jul 08, 2009 at 04:29:40PM +0100, Kevin Wright wrote:
> On the other hand, if it does work, then we have a convenient shortcut
> to auto-generate extractors and equality methods on mutable objects.

I don't know what's supposed to be happening in the original code, but
are case classes not a short enough shortcut for you?

scala> case class Foo(var x: Int, var y: Int)
defined class Foo

scala> val x = Foo(5,10)
x: Foo = Foo(5,10)

scala> val y = Foo(5,10)
y: Foo = Foo(5,10)

scala> x == y
res0: Boolean = true

scala> x.y = 20

scala> x == y  
res1: Boolean = false

--
Paul Phillips      | Every election is a sort of advance auction sale
Everyman           | of stolen goods.
Empiricist         |     -- H. L. Mencken
pull his pi pal!   |----------* http://www.improving.org/paulp/ *----------

 « Return to Thread: equals in case class does not seem to be working...