Something like this compiles:
// Start writing your ScalaFiddle code here
abstract class Bdd (val ident:Int) {}
case class BddNode(label:Int, positive:Bdd, negative:Bdd) extends Bdd(Bdd.nextIdent()) {
override def equals(that:Any):Boolean = {
this eq that.asInstanceOf[AnyRef]
}
override def hashCode(): Int =
System.identityHashCode(this)
}
object Bdd {
var currentIdent = 2
def nextIdent(): Int = {
currentIdent += 1
currentIdent - 1
}
}
and gives following result:
val a = BddNode(5, null, null)
val b = BddNode(5, null, null)
println(a == b) // prints false
PS:
I’m not sure if overridding hashCode is needed. In fact fixed hashCode compiles with contract, but performance is impacted.