Hi,
It works for
Groovy Version: 1.0-beta-7 JVM: 1.4.2-38
The script that I ran is
#!/usr/bin/env groovy
import java.math.max;
int i = 1;
println Math.max( 2, i );
and the execution of the scripts gives the answer '2".
Best Regards,
On 17-Nov-04, at PM 12:53, Pascal DeMilly wrote:
Actually it doesn't work either. defining my own max(Integer l, Integer
r) worked but I was not able to use the Math.max function. I get the
following error message:
Caught: groovy.lang.GroovyRuntimeException: Ambiguous method
overloading for method: max. Cannot resolve which method to invoke due
to overlapping prototypes between: [double, double] and: [float,
float]
groovy.lang.GroovyRuntimeException: Ambiguous method overloading for
method: max. Cannot resolve which method to invoke due to overlapping
prototypes between: [double, double] and: [float, float]
I simplified the code to its minimum
import java.math.max;
i = 10;
println Math.max ((int) 2, (int) i);
I don't know why it doesn't see Math.max(int, int). Just to make sure I
changed the int cast to a float cast and got the same error message. So
something is really wrong with the type conversion. It is in my limited
experience with groovy where I spend the most time trying to figure
what
groovy translated what in what. It is not my preferred part of the
language for sure.
Anyway continue the good work. There are plenty of positives.
Pascal
On Tue, 2004-11-16 at 07:58, Pascal DeMilly wrote:
Robert,
Thanks! You are absolutely right. I should have call Math.max not max.
Thanks again
Pascal
On Tue, 2004-11-16 at 07:38, Robert McIntosh wrote:
It appears you have to use the class for the static, unlike 1.5's
static
imports:
print Math.max(0, qoh)
should work.
The message you were seeing was a little confusing, it was actually
saying
that it could not find a method called max with two Integer args on
your
script, not on Math.
- Robert
Tuesday, November 16, 2004 9:05 AM
To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@xxxxxxxxxxxxxxxx
cc:
From: Pascal DeMilly <list.groovy-MAs0IwSbNVGU+1/U8MakDg@xxxxxxxxxxxxxxxx>
Subject: [groovy-user] Auto type conversion
I am writing a small script that use the java.Math.max method. The
problem I am having is that groovy insists on transforming my int to
Integer. Since max doesn't have a prototype for (Integer, Integer)
groovy issues an Exception. How can I force groovy to pass an (int,
int)
to max
import java.Math.max;
<snip>
mydb.eachRow ("SELECT * from Items) {
int qoh = it.QtyOnHand.intValue()
print max(0, qoh) // Exception
}
TIA
Pascal
|