2

代码看起来像

public void option() {
    seeTasks = tasks.getTasks();
        for (int i = 0; i < seeTasks.size(); i++) {
            for (int b = 0; b < seeBoxes.size(); b++) {
               System.out.println("see Tasks: " + seeTasks.get(i) + 
                           " see Boxes " + seeBoxes.get(b));
            if(seeTasks.get(i) == seeBoxes.get(b)) {
                option.add(seeTasks.get(i));
            }
        }
    }
    System.out.println(option);
}

如果的值 低于 150 ,则if语句seeTaks.get(i)不会通过。这怎么可能?seeTasks.get(i)如下所示,370 不包括在内。如果我将 110 更改为 150,它将无法通过。

println's 的输出是:

see Tasks: 50 see Boxes 50
see Tasks: 50 see Boxes 110
see Tasks: 50 see Boxes 150
see Tasks: 50 see Boxes 210
see Tasks: 50 see Boxes 270
see Tasks: 50 see Boxes 310
see Tasks: 50 see Boxes 370
see Tasks: 50 see Boxes 430
see Tasks: 110 see Boxes 50 
see Tasks: 110 see Boxes 110
see Tasks: 110 see Boxes 150
see Tasks: 110 see Boxes 210
see Tasks: 110 see Boxes 270
see Tasks: 110 see Boxes 310
see Tasks: 110 see Boxes 370
see Tasks: 110 see Boxes 430
see Tasks: 370 see Boxes 50
see Tasks: 370 see Boxes 110
see Tasks: 370 see Boxes 150
see Tasks: 370 see Boxes 210
see Tasks: 370 see Boxes 270
see Tasks: 370 see Boxes 310
see Tasks: 370 see Boxes 370
see Tasks: 370 see Boxes 430
[50, 110]
4

1 回答 1

5

我猜测

seeTasks.get(i)

seeBoxes.get(b)

两者都返回一个Integer. 然后对于低于 128 的值,Integer缓存返回相同的实例,但对于较大的值,则返回新实例。使用equals().

于 2013-01-16T00:01:15.297 回答