无论如何,我很好奇是否可以创建一个扩展
   
    ByteBuffer
   
   .  我以为这是不可能的,因为
   
    比特布弗
   
   拥有包专用构造函数:
  
  // package-private
ByteBuffer(int mark, int pos, int lim, int cap, byte[] hb, int offset) {
    super(mark, pos, lim, cap);
    this.hb = hb;
    this.offset = offset;
}
// Creates a new buffer with the given mark, position, limit, and capacity
//
ByteBuffer(int mark, int pos, int lim, int cap) { // package-private
    this(mark, pos, lim, cap, null, 0);
}
  
   但是,我发现如果您在与父类共享名称的包中创建类,那么它将完全编译。
  
  package java.nio;
public class Test extends ByteBuffer {
    Test(int mark, int pos, int lim, int cap, byte[] hb, int offset) {
        super(mark, pos, lim, cap, hb, offset);
    }
    @Override
    public ByteBuffer slice() {
        return null;
    }
    ...
}   
  
   它也可以在Java9和Java10中编译,但只有在使用
   
    --patch-module
   
   编译时:
  
  javac --patch-module java.base=. java/nio/Test.java
  
   我的问题是:这是如何(为什么)编译的?