死代码错误

时间:2010-08-22 17:50:27

标签: java dead-code

我在这个Java代码片段中使用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++;
        }
}

1 个答案:

答案 0 :(得分:8)

if语句仅检查来自Equipment类的最终静态值,并且编译器检测到此条件永远不会是true,因此以下行是死代码(无法访问)。