The parameters of the java function cannot be set to a default value solution

Java cannot set default parameters for functions (methods) . The reason is that "default parameters" and "method overloading" are ambiguous if they are supported at the same time, but using "method overloading" can indirectly achieve the effect of "default parameters"

    public boolean func(boolean isTrue){
         return isTrue;  
    }
 ​
    //使用方法重载,实现参数默认值
    public boolean func(){
         return func(true);
    }

Guess you like

Origin blog.csdn.net/wh445306/article/details/131736380