有一类java笔试题是考察对于装箱缓存的理解,这方面,Java Language Specification(8)中是这样描述的:
If the value p being boxed is an integer literal of type int between -128 and 127 inclusive (§3.10.1), or the boolean literal true or false (§3.10.3), or a character literal between ‘\u0000’ and ‘\u007f’ inclusive (§3.10.4), then let a and b be the results of any two boxing conversions of p. It is always the case that a == b.
装箱对于Integer和Char类型是有效的,对于-128到127、以及’\u0000’ 到’\u007f’的Char,只要值一样,这两个对象的引用就是相等的。