scala - Call to == does not opt to equals -
i have following class:
abstract class irdmessage extends ordered[irdmessage] { val messagetype: messagetype.type val timestamp: datetime val content: anyref def compare(that: irdmessage): int = { val res = timestamp compareto that.timestamp res } override def equals(obj: any): boolean = obj match{ case message: irdmessage => compareto(message) == 0 case _ => false } }
i have couple of concrete implementations well. however, when try a == b
of subtype of irdmessage equals method not called , compares references (default equals implementation). ideas might causing this?
the subclasses simple case classes btw.
this work given following simplified example:
object messagetest { def main(args: array[string]) { val m1 = messageimpl("foo") val m2 = messageimpl("bar") m1 == m2 } } abstract class irdmessage extends ordered[irdmessage] { val content: anyref override def equals(obj: any): boolean = { println("in here") obj match{ case message: irdmessage => compareto(message) == 0 case _ => false } } } case class messageimpl(content:string) extends irdmessage{ override def compare(that:irdmessage) = 0 }
can post little more code, 1 of sample case classes? noticed if defined case class so:
case class messageimpl extends irdmessage{ var content = "foo" override def compare(that:irdmessage) = 0 }
it not work expected.
Comments
Post a Comment