就个人而言,我从未理解工厂类的想法,因为直接实例化一个Object似乎更有用.我的问题很简单,在什么情况下使用工厂类模式是最佳选择,出于什么原因,以及良好的工厂类是什么样的?
当我使用 netty 向网络服务器发送请求时。我得到以下异常。什么会导致这个异常?
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.7.0_25]
at sun.nio.ch.SocketDispatcher.read(Unknown Source) ~[na:1.7.0_25]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) ~[na:1.7.0_25]
at sun.nio.ch.IOUtil.read(Unknown Source) ~[na:1.7.0_25]
at sun.nio.ch.SocketChannelImpl.read(Unknown Source) ~[na:1.7.0_25]
at io.netty.buffer.UnpooledHeapByteBuf.setBytes(UnpooledHeapByteBuf.java:237) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:867) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:227) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:87) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:497) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:465) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:359) ~[netty-all-4.0.6.Final.jar:na]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) ~[netty-all-4.0.6.Final.jar:na]
at java.lang.Thread.run(Unknown Source) ~[na:1.7.0_25]
Run Code Online (Sandbox Code Playgroud) java中是否有一个Collection:
我似乎无法找到任何只是通过搜索谷歌/ javadocs感谢您的帮助!
我试图重载() operator接受a long,代码在下面.
struct print{
void operator()(long x){
printf("Number: %d\n",x);
}
};
Run Code Online (Sandbox Code Playgroud)
但是,当我这样写:
print p();
long l = 10;
p(l);
Run Code Online (Sandbox Code Playgroud)
编译器在对应的行上大喊"错误:函数调用中的参数太多" p(l);
为什么这不起作用,我() operator是否正确超载?