自动箱子有助于开发商创建与“转移”收集方法有关的ug,尽管这可能是一种很模糊的 b子。
I ve encountered this bug when I used a random number generator to select the index of an item to remove from an ArrayList. The generator returned a long primitive, which I accidentally tried to use as the parameter for List.remove(int index). The compiler converted the long to a Long and used it in List.remove(Object o), which gave totally different behavior. Luckily, an assert statement caught the error quickly.
According to this discussion of this issue with "remove", someone else ran into a similar problem where their int unexpectedly acted like an Integer, though I don t understand how that happened.
Why aren t Java Collections remove methods generic?
(see comment by ScArcher2)