简体   繁体   English

无法实例化SocketChannel类型

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM