代码之家  ›  专栏  ›  技术社区  ›  sofs1 Romain Manni-Bucau

为什么Java设计器没有为具有不同顺序的相同参数的重载方法创建错误?[暂停]

  •  2
  • sofs1 Romain Manni-Bucau  · 技术社区  · 5 年前
    class Ideone
    {
        public static void main (String[] args) throws java.lang.Exception
        {
            // your code goes here
    
            Tree t = new Tree();
            t.cutTree("saw", 10);
            t.cutTree(10, "knife");
    
        }
    
        static class Tree{
    
            public static void cutTree(String instrument, int cutLength){
                System.out.println("first method");
            }
    
            public static void cutTree(int cutLength, String instrument){
                System.out.println("second method");
            }
    
        }
    }
    

    Java的创造者在这背后的推理是什么?

    0 回复  |  直到 5 年前