Overloading with variable args

前端 未结 1 416
臣服心动
臣服心动 2021-01-16 12:01
class OverloadingVarargs2 {
    static void f(float i, Character... args) {
        System.out.println(\"first\");
        System.out.println(i);
    }
    static vo         


        
相关标签:
1条回答
  • 2021-01-16 12:37

    That is because there is no way to determine if that method call should either call the one with variable args or the one with float and variable args.

    Java decides with method to call in this way widening > boxing > variable args, however in this case both have variable args.

    Basically char is being widened to float in this scenario.

    The widening order for java primitives is:

    byte -> short -> int -> long -> float -> double
    char -> int -> long -> float -> double
    
    0 讨论(0)
提交回复
热议问题