gpt4 book ai didi

java - 为什么 Eclipse 用 'parameter is hiding a field' 标记私有(private)方法,而不是公共(public)方法?

转载 作者:行者123 更新时间:2023-11-30 02:11:04 28 4
gpt4 key购买 nike

在本类(class)中:

class RuleSet {
private final Collection<Rule> rules = new ArrayList<>();

public void setRules(Collection<Rule> rules) {
replaceRules(rules);
// do something else here...
}

private void replaceRules(Collection<Rule> rules) {
this.rules.clear();
this.rules.addAll(rules);
}
}

Eclipse(Oxygen.3a 版本 (4.7.3a))对私有(private)方法设置警告 the parameter rules is hiding a field from the type RuleSet ,但不适用于具有相同参数名称的公共(public)方法。

为什么其中一个是潜在问题,而另一个却不是?

最佳答案

是否出现警告取决于您的 Eclipse -> Java 设置(参见图片)。

局部变量声明隐藏另一个字段或变量设置为警告以查看示例中的警告。

或者甚至设置包含构造函数或setter方法参数以在setter中存在名称隐藏时收到警告。这也会在您的 setter 和 getter 中显示警告。

enter image description here

关于java - 为什么 Eclipse 用 'parameter is hiding a field' 标记私有(private)方法,而不是公共(public)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50112041/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com