Does Java support default parameter values?

后端 未结 25 2003
清歌不尽
清歌不尽 2020-11-22 07:07

I came across some Java code that had the following structure:

public MyParameterizedFunction(String param1, int param2)
{
    this(param1, param2, false);
}         


        
25条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 07:35

    Try this solution:

    public int getScore(int score, Integer... bonus)
    {
        if(bonus.length > 0)
        {
            return score + bonus[0];
        }
    
        return score;
    }
    

提交回复
热议问题