Hello,
trying to overload the java.lang.Math.sqrt
static method for int
type :
import static java.lang.Math.sqrt;
class Test
{
private static double sqrt(int n)
{
return sqrt(1.0 * n);
}
public static void main(String[] args)
{
System.out.println(sqrt(1));
}
}
an odd error arises :
Test.java:7: sqrt(int) in Test cannot be applied to (double)
return sqrt(1.0 * n);
^
1 error
But when explicitly referencing the java.lang.Math.sqrt
method all is going fine :
class Test
{
private static double sqrt(int n)
{
return Math.sqrt(1.0 * n);
}
public static void main(String[] args)
{
System.out.println(sqrt(1));
}
}
The compiler used is the standard javac, version 1.6.0_16.
So the questions are :
- Why is the compiler not able to resolve the overloading in the first case ?
- Where does this behavior is specified in the java language specifications ?
Thanks in advance.