Java中装箱时的缓存

    xiaoxiao2023-03-24  2

    有一类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,只要值一样,这两个对象的引用就是相等的。

    转载请注明原文地址: https://ju.6miu.com/read-1201310.html
    最新回复(0)