只是添加到其他所有的正確答案,看看在source code,以充分了解@mmyers在說:
584 /**
585 * Returns an {@code Integer} instance representing the specified
586 * {@code int} value. If a new {@code Integer} instance is not
587 * required, this method should generally be used in preference to
588 * the constructor {@link #Integer(int)}, as this method is likely
589 * to yield significantly better space and time performance by
590 * caching frequently requested values.
591 *
592 * @param i an {@code int} value.
593 * @return an {@code Integer} instance representing {@code i}.
594 * @since 1.5
595 */
596 public static Integer valueOf(int i) {
597 final int offset = 128;
598 if (i >= -128 && i <= 127) { // must cache
599 return IntegerCache.cache[i + offset];
600 }
601 return new Integer(i);
602 }
來源
2010-03-23 13:06:32
Tom
這樣一個具體問題,嗯,可疑 – Will 2010-03-23 13:01:06
@Will我在一本SCJP書中看到過同樣的問題 – 2010-03-23 13:07:10
我敢打賭,它返回false,true,false,true而不是true,true,false,true – 2010-03-23 13:10:18