以bytebuffer为例
allocate方法的源码
public static ByteBuffer allocate(int capacity) {
if (capacity < 0)
throw new IllegalArgumentException();
return new HeapByteBuffer(capacity, capacity);
}
heapbytebuffer的源码 。只不过调用的bytebuffer的构造器
HeapByteBuffer(int cap, int lim) { // package-private
super(-1, 0, lim, cap, new byte[cap], 0);
/*
hb = new byte[cap];
offset = 0;
*/
}
为什么不直接调用bytebuffer的构造器,而是要通过heapbytebuffer调用bytebuffer构造器