- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
what's wrong with this?
Wed, 2010-09-22, 23:04
scala> 1 compareTo 2 <console>:5: error: type mismatch; found : Int required: ?{val compareTo: ?} Note that implicit conversions are not applicable because they are ambiguous: both method int2Integer in object Predef of type (Int)java.lang.Integer and method intWrapper in object Predef of type (Int)scala.runtime.RichInt are possible conversion functions from Int to ?{val compareTo: ?} 1 compareTo 2 ^
--
Thanks,
-Vlad
Wed, 2010-09-22, 23:37
#2
Re: what's wrong with this?
On Wed, Sep 22, 2010 at 03:04:06PM -0700, Vlad Patryshev wrote:
> scala> 1 compareTo 2
Of course I say that, and then looking at it I can't immediately figure
out why it works now... I thought it was safe to jump to the conclusion
it was some brilliant move on my part, but horrors that might not be.
It seems likely to have begun working when I added these:
implicit def Byte2byte(x: java.lang.Byte): Byte = x.byteValue
implicit def Short2short(x: java.lang.Short): Short = x.shortValue
implicit def Character2char(x: java.lang.Character): Char = x.charValue
implicit def Integer2int(x: java.lang.Integer): Int = x.intValue
implicit def Long2long(x: java.lang.Long): Long = x.longValue
implicit def Float2float(x: java.lang.Float): Float = x.floatValue
implicit def Double2double(x: java.lang.Double): Double = x.doubleValue
implicit def Boolean2boolean(x: java.lang.Boolean): Boolean = x.booleanValue
However the ambiguous implicits to RichInt and Integer are still both
present, and now for some reason RichInt wins even though they're both
defined in Predef. I have to run but I'm counting on someone out there
to figure this out and reassure me brilliance was involved somewhere.
Wed, 2010-09-22, 23:47
#3
Re: what's wrong with this?
Looks like it was fixed in 2.8.1 RC1
Welcome to Scala version 2.8.1.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1 compareTo 2
res0: Int = -1
On Wed, Sep 22, 2010 at 4:27 PM, Paul Phillips <paulp@improving.org> wrote:
Welcome to Scala version 2.8.1.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1 compareTo 2
res0: Int = -1
On Wed, Sep 22, 2010 at 4:27 PM, Paul Phillips <paulp@improving.org> wrote:
On Wed, Sep 22, 2010 at 03:04:06PM -0700, Vlad Patryshev wrote:
> scala> 1 compareTo 2
Of course I say that, and then looking at it I can't immediately figure
out why it works now... I thought it was safe to jump to the conclusion
it was some brilliant move on my part, but horrors that might not be.
It seems likely to have begun working when I added these:
implicit def Byte2byte(x: java.lang.Byte): Byte = x.byteValue
implicit def Short2short(x: java.lang.Short): Short = x.shortValue
implicit def Character2char(x: java.lang.Character): Char = x.charValue
implicit def Integer2int(x: java.lang.Integer): Int = x.intValue
implicit def Long2long(x: java.lang.Long): Long = x.longValue
implicit def Float2float(x: java.lang.Float): Float = x.floatValue
implicit def Double2double(x: java.lang.Double): Double = x.doubleValue
implicit def Boolean2boolean(x: java.lang.Boolean): Boolean = x.booleanValue
However the ambiguous implicits to RichInt and Integer are still both
present, and now for some reason RichInt wins even though they're both
defined in Predef. I have to run but I'm counting on someone out there
to figure this out and reassure me brilliance was involved somewhere.
--
Paul Phillips | It is hard to believe that a man is
In Theory | telling the truth when you know that you
Empiricist | would lie if you were in his place.
i pull his palp! | -- H. L. Mencken
On Wed, Sep 22, 2010 at 03:04:06PM -0700, Vlad Patryshev wrote:
> scala> 1 compareTo 2
> :5: error: type mismatch;
> found : Int
> required: ?{val compareTo: ?}
> Note that implicit conversions are not applicable because they are ambiguous:
> both method int2Integer in object Predef of type (Int)java.lang.Integer
> and method intWrapper in object Predef of type (Int)scala.runtime.RichInt
> are possible conversion functions from Int to ?{val compareTo: ?}
> 1 compareTo 2
> ^
What's wrong with it is just what it looks like, ambiguity between
multiple routes from Int => compareTo. But do not fret! I got this one.
% scala29
Welcome to Scala version 2.9.0.r23057-b20100921235119 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1 compareTo 2
res0: Int = -1