使用引用时 BlueJ 中的 Java checkstyle 错误
我正在使用 BlueJ 作为 IDE 用 Java 编写算法。我使用 trackback 算法来解决问题,除了 checkstyle 之外,一切都运行良好。检查样式错误是:
Assignment of parameter i is not allowed [on line 336]
Assignment of parameter j is not allowed [on line 337]
但是,由于引用要求将变量作为参数传递,并且还根据情况进行编辑,所以我对此无能为力。
有人知道如何解决这个问题吗?这是我的代码(错误行已注释):
public boolean solve(int i, int j) {
if (i == 9) {
i = 0; // line 336
if (++j == 9) { // line 337
return true;
}
}
...
for (int value = 1; value <= 9; ++value) {
if (possible[value]) {
setCell(i,j,value);
if (solve(i+1,j)) {
return true;
}
}
}
game[i][j] = 0;
return false;
}
I'm doing an algorithm in Java using BlueJ as an IDE. I use trackback algorithm to solve the problem and everything works perfectly except for the checkstyle. The checkstyle errors are:
Assignment of parameter i is not allowed [on line 336]
Assignment of parameter j is not allowed [on line 337]
However, as trackback requires the variables to be passed as the arguments and also be edited according to the situation, so I can't do anything about this.
Does anybody know how to fix this? This is my code (error lines are commented):
public boolean solve(int i, int j) {
if (i == 9) {
i = 0; // line 336
if (++j == 9) { // line 337
return true;
}
}
...
for (int value = 1; value <= 9; ++value) {
if (possible[value]) {
setCell(i,j,value);
if (solve(i+1,j)) {
return true;
}
}
}
game[i][j] = 0;
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会收到警告,因为 Checkstyle 认为修改方法参数是一种不好的做法。如果您不认为这是不好的做法,请忽略它(或更改 checkstyle 配置),或者更改代码以处理参数的副本:
You get a warning because Checkstyle considers that modiying method arguments is a bad practice. Either ignore it (or change the checkstyle config) if you don't consider it as bad practice, or change the code to work on copies of the arguments: