ByteCache

 private static class ByteCache {
        private ByteCache(){}
    //256个元素,用于缓存-128到127
        static final Byte cache[] = new Byte[-(-128) + 127 + 1];

        static {
            for(int i = 0; i < cache.length; i++)
                cache[i] = new Byte((byte)(i - 128));
        }
    }

  Byte的valueof方法

  public static Byte valueOf(byte b) {
        final int offset = 128;
        return ByteCache.cache[(int)b + offset];
    }

  

原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/6901759.html