In this 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 Release (4.7.3a)) sets a warning on the private method that the parameter rules is hiding a field from the type RuleSet
, but not on the public method that has the same parameter name.
Why is one a potential problem but not the other?
If the warnings occur depends on your Eclipse -> Java settings (see image).
Set Local variable declaration hides another field or variable
to warning to see the warnings from your example.
Or even set Include constructor or setter method parameters
to get warnings if there is name shadowing in setters. This would show warnings in your setters and getters too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.