Can anyone enlighten me as to why implicit type conversion does not work with ==
?
Example:
class BitArray(l: Int, v: Long) {
val length = l
var value = v
def ==(that: BitArray) = value == that.value
def ==(integer: Long) = value == integer
def +(that: BitArray) = new BitArray(length,value+that.value )
def +(integer: Long) = new BitArray(length,value+integer )
//...
}
object BitArray{
implicit def longToBitArray(x : Long) = new BitArray(64,x)
def apply(v: Long) :BitArray = apply(64,v)
}
Now I can do:
scala> BitArray(5) + 5
res13: BitArray = 00000000000000000000000000001010
scala> 5 + BitArray(5)
res14: BitArray = 00000000000000000000000000001010
scala> BitArray(5) == 5
res15: Boolean = true
scala> BitArray(5) == 6
res16: Boolean = false
BUT:
scala> 5 == BitArray(5)
<console>:11: warning: comparing values of types Int and BitArray using `==' will
always yield false
5 == BitArray(5)
^
res17: Boolean = false