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");
   }
}

解决方案 »

  1.   

    当小数点出现时,系统默认为是DOUBLE
      

  2.   

    第二个TEST()不符合,所以向高级转化
      

  3.   

    superLee(superLee)兄 你在试试这个class Example2 {
       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");
       }
    }
      

  4.   

    我觉得关键在"5L"这个参数,它明确表示这个5用long型存储。
    所以调用的是test(int a, float b, long c)方法。
      

  5.   

    superLee(superLee) 说的不错
    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