gpt4 book ai didi

java - 鱿鱼 :S2583 : Change this condition so that it does not always evaluate to "true"

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

S2583:如何更改条件 ps != null 使其不总是计算为“false”?

PreparedStatement ps = null;
if (ps != null) {
try {
ps.close();
} catch (SQLException uncatched) {
uncatched.printStackTrace();
}
}

最佳答案

如果 ps 不为 null,因为您总是为其设置一个值(在您省略的行处),则条件语句完全多余,您可以消除该条件。

来自鱿鱼:S2583描述:

Conditional statements using a condition which cannot be anything but FALSE have the effect of making blocks of code non-functional. If the condition cannot evaluate to anything but TRUE, the conditional statement is completely redundant, and makes the code less readable.

关于java - 鱿鱼 :S2583 : Change this condition so that it does not always evaluate to "true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35215944/

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