Checkstyle 提到了”条件逻辑可以被移除”吗?

huangapple go评论79阅读模式
英文:

Checkstyle saying "Conditional logic can be removed"?

问题

这是 Checkstyle 不喜欢的部分,具体来说是 "if (eggs >= 3)" 这一行。我该如何更改以使其通过 Checkstyle?

if (flour >= 1) 
{
    if (sugar >= 2) 
    {
        if (eggs >= 3) 
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    else 
    {
        return false;
    }
}
英文:

This is the part that checkstyle doesn't like, specifically the "if (eggs >= 3)" line. How can I change this to make it pass for checkstyle?

if (flour >= 1) 
    {
        if (sugar >= 2) 
        {
            if (eggs >= 3) 
            {
                return true;
            }
            else 
            {
                return false;
            }

        }
        else 
        {
            return false;
        }

答案1

得分: 1

public static boolean foo(int flour, int sugar, int eggs) {
    return flour >= 1 && sugar >= 2 && eggs >= 3;
}
英文:
public static boolean foo(int flour, int sugar, int eggs) {
    return flour >=1 && sugar >= 2 && eggs >=3;
}

huangapple
  • 本文由 发表于 2020年10月1日 05:56:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64146297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定