[英]Methods and field names should not differ only by capitalization (squid:S1845) false positive
I have a field name which is similar to static constant我有一个类似于静态常量的字段名称
public static final String MAIL = "mail";
private String mail;
I'm getting sonar warning:我收到声纳警告:
`Methods and field names should not be the same or differ only by capitalization (squid:S1845)`
Although field is instance and constant isn't a method and also static虽然字段是实例,常量不是方法,也是静态的
Is it false positive sonar warning, a corner case I should suppress or is there a real issue in my code and I need to move constant outside class (or inner class)?是误报声纳警告,我应该抑制的极端情况还是我的代码中存在真正的问题并且我需要将常量移到类(或内部类)之外?
I found other false positive for this warning, but it was fixed, Builder pattern :我发现此警告的其他误报,但已修复, Builder 模式:
S1845 should not raise issue on builders and methods returning the field with same name
S1845 不应引发返回同名字段的构建器和方法的问题
It wouldn't cause an issue when building your source code, so from that perspective you could suppress it, but it might generate confusion to the developer/reviewer, so it would be best to fix it (especially when working with autocomplete, although the field is private in this case...) .在构建源代码时它不会导致问题,因此从这个角度来看,您可以抑制它,但它可能会给开发人员/审查者带来混乱,因此最好修复它(尤其是在使用自动完成功能时,尽管在这种情况下,字段是私有的...)。 Maybe use a different naming pattern for local variables.
也许对局部变量使用不同的命名模式。 Different scope would also fix this.
不同的范围也可以解决这个问题。
I found also this link where they try to describe this, although they focus mostly on methods, and the 'Compliant Solution' is in tune with the links you've shared regarding the BuilderPattern: https://rules.sonarsource.com/java/tag/confusing/RSPEC-1845我还发现了他们试图描述这一点的链接,尽管他们主要关注方法,并且“合规解决方案”与您分享的关于 BuilderPattern 的链接一致: https ://rules.sonarsource.com/java /标签/混淆/ RSPEC-1845
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.