Simple Scala syntax - trying to define "==" operator - what am I missing?
Posted
by Alex R
on Stack Overflow
See other posts from Stack Overflow
or by Alex R
Published on 2010-04-21T01:42:37Z
Indexed on
2010/04/21
1:43 UTC
Read the original article
Hit count: 238
While experimenting with some stuff on the REPL, I got to a point where I needed something like this:
scala> class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } }
Just a simple class with an "==" operator.
Why doesn't it work???
Here's the result:
:10: error: type mismatch; found : A required: ?{val x: ?} Note that implicit conversions are not applicable because they are ambiguous: both method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A] and method any2Ensuring in object Predef of type [A](x: A)Ensuring[A] are possible conversion functions from A to ?{val x: ?} class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } } ^
This is scala 2.8 RC1.
Thanks
© Stack Overflow or respective owner