0
06
41
16
为了账号安全,请及时绑定邮箱和手机立即绑定

Vector源码疑惑

Vector源码疑惑

蝴蝶刀刀 2019-03-13 18:15:04
1.在看Vector源码是有2个小知识点比较疑惑2.疑惑代码如下/**This implements the unsynchronized semantics of ensureCapacity.Synchronized methods in this class can internally call thismethod for ensuring capacity without incurring the cost of anextra synchronization.*@see #ensureCapacity(int)*/void ensureCapacityHelper(int minCapacity) {   // overflow-conscious code    if (minCapacity - elementData.length > 0)        grow(minCapacity);}/**The maximum size of array to allocate.Some VMs reserve some header words in an array.Attempts to allocate larger arrays may result inOutOfMemoryError: Requested array size exceeds VM limit*/static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;3.疑惑问题点如下:问题点1:if (minCapacity - elementData.length > 0),为啥不这样写if(minCapacity>elementData.length),效率高在哪?问题点2:MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;为啥是减8而不是其他,注释没看明白是啥意思
查看完整描述

1 回答

没有找到匹配的内容?试试慕课网站内搜索吧

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号