菜菜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 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];
    }

  

posted on 2017-05-25 01:17  好吧,就是菜菜  阅读(412)  评论(0编辑  收藏  举报