[英]Cannot instantiate the type SocketChannel
According to the docs, I can do this: 根据文档,我可以这样做:
SocketChannel mySocketChannel = new SocketChannel(SelectorProvider.provider());
According to JDK I can not. 根据JDK我不能。
Simple question: Why am I getting the error in the title? 简单的问题:为什么我在标题中收到错误?
The constructor is protected
, meaning only inherited classes can access it to inherit its base functionality (notice that SocketChannel
inherits from AbstractSelectableChannel
). 构造函数
protected
,这意味着只有继承的类才能访问它以继承其基本功能(请注意SocketChannel
继承自AbstractSelectableChannel
)。
To open a SocketChannel
, use the static open
method: 要打开
SocketChannel
,请使用静态open
方法:
SocketChannel socketChannel = SocketChannel.open();
See the SocketChannel Documentation and an example . 请参阅SocketChannel文档和示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.