Java overload confusion

后端 未结 4 1440
广开言路
广开言路 2020-12-19 14:13

java is not able to call any overload method as shown below :-

class LspTest{

    public void add(int a, float b){
    System.out.println(\"First add\");
}         


        
4条回答
  •  难免孤独
    2020-12-19 14:32

    There is an ambiguity here, and the Java compiler cannot figure out which method to call. Use test.add((float) 1, 1) or test.add(1, (float) 1) to explicitly tell which method you want.

提交回复
热议问题