admin管理员组文章数量:1611949
2019独角兽企业重金招聘Python工程师标准>>>
ByteBuffer是个抽象类:
//4个
public abstract class Buffer {
private int mark = -1;
private int position = 0;
private int limit;
private int capacity;
}
//2个数据成员
public abstract class ByteBuffer
extends Buffer
implements Comparable<ByteBuffer>
{
final byte[] hb; // Non-null only for heap buffers
final int offset;
// boolean isReadOnly; // Valid only for heap buffers
}
public static ByteBuffer allocate(int capacity) {
if (capacity < 0)
throw new IllegalArgumentException();
return new HeapByteBuffer(capacity, capacity);//使用的是抽象基类,在基类中返回子类对象
}
class HeapByteBuffer extends ByteBuffer{
HeapByteBuffer(int cap, int lim) {//子类构造函数,调用基类构造函数构造成员
super(-1, 0, lim, cap, new byte[cap], 0);
/*
hb = new byte[cap];
offset = 0;
*/
/*
ByteBuffer(int mark, int pos, int lim, int cap, // package-private
byte[] hb, int offset)
{
super(mark, pos, lim, cap);
this.hb = hb;
this.offset = offset;
}
*/
/*
Buffer(int mark, int pos, int lim, int cap) { // package-private
if (cap < 0)
throw new IllegalArgumentException("Negative capacity: " + cap);
this.capacity = cap;
limit(lim);
position(pos);
if (mark >= 0) {
if (mark > pos)
throw new IllegalArgumentException("mark > position: ("
+ mark + " > " + pos + ")");
this.mark = mark;
}
}
*/
}
}
转载于:https://my.oschina/zengjs275/blog/1507405
本文标签: allocateByteBufferCapacityINT
版权声明:本文标题:ByteBuffer.allocate(int capacity)的理解 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728621255a1166386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论