死代码错误
我在使用 Eclipse 的 Java 代码片段中遇到死代码错误:
public void rebirthAction() {
Player p = new Player(null);
Equipment e = new Equipment();
Skills s = new Skills(null);
if ((Equipment.SLOT_SHIELD == -1) && (Equipment.SLOT_WEAPON == -1) && (Equipment.SLOT_CHEST == -1) && (Equipment.SLOT_BOTTOMS == -1) && (Equipment.SLOT_AMULET == -1) && (Equipment.SLOT_BOOTS == -1) && (Equipment.SLOT_HELM == -1) && (Equipment.SLOT_GLOVES == -1))
for (int i = 0; i <= 7; i++) {
p.getSkills().setLevel(i, 1);
p.getSkills().setExperience(i, 0);
//updateRequired = true;
//appearanceUpdateRequired = true;
s.getTotalLevel();
s.getCombatLevel();
Combat.calculateMaxHit(p);
p.getSkills();
rebirthCount++;
}
}
I'm getting a dead code error in this Java code snippet, using Eclipse:
public void rebirthAction() {
Player p = new Player(null);
Equipment e = new Equipment();
Skills s = new Skills(null);
if ((Equipment.SLOT_SHIELD == -1) && (Equipment.SLOT_WEAPON == -1) && (Equipment.SLOT_CHEST == -1) && (Equipment.SLOT_BOTTOMS == -1) && (Equipment.SLOT_AMULET == -1) && (Equipment.SLOT_BOOTS == -1) && (Equipment.SLOT_HELM == -1) && (Equipment.SLOT_GLOVES == -1))
for (int i = 0; i <= 7; i++) {
p.getSkills().setLevel(i, 1);
p.getSkills().setExperience(i, 0);
//updateRequired = true;
//appearanceUpdateRequired = true;
s.getTotalLevel();
s.getCombatLevel();
Combat.calculateMaxHit(p);
p.getSkills();
rebirthCount++;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
if
语句仅检查 Equipment 类中的最终静态值,并且编译器检测到此条件永远不可能为true
,因此以下行是死代码(无法访问)。The
if
statement only checks final static values from the Equipment class and the compiler detects, that this condition can never betrue
so the following lines are dead code (unreachable).