5.0 java可判断为double,也可判断为float,
我测试时两种结果都出现,但下面的代码是唯一的结果,
^_^结贴吧
class Example2 {
public static void main(String[] args) {
Example2 e = new Example2();
e.test(5, 5.0F, 5L);
//e.test(5, 5.0, 5L);
}
void test(double a, double b, double c) {
System.out.println("double, double, double");
}
void test(int a, float b, long c) {
System.out.println("int, float, long");
}
}
我测试时两种结果都出现,但下面的代码是唯一的结果,
^_^结贴吧
class Example2 {
public static void main(String[] args) {
Example2 e = new Example2();
e.test(5, 5.0F, 5L);
//e.test(5, 5.0, 5L);
}
void test(double a, double b, double c) {
System.out.println("double, double, double");
}
void test(int a, float b, long c) {
System.out.println("int, float, long");
}
}
public static void main(String[] args) {
Example2 e = new Example2();
e.test(5, 5.0, 5L);
}
void test(double a, double b, double c) {
System.out.println("float, double, double");
}
void test(int a, float b, long c) {
System.out.println("int, double, long");
}
}
所以调用的是test(int a, float b, long c)方法。
JAVA中把5.0看成是DOUBLE的
具体测试如下:
class Example2 {
public static void main(String[] args) {
Example2 e = new Example2();
e.test(5, 5.0, 5L);
}
void test(int a, double b, long c) {
System.out.println("int, float, long");
}
void test(int a, float b, long c) {
System.out.println("double, double, double");
}
}
结果是:int, float, long