我在玩 scala(新手),我正在尝试使用 Java 7 NIO(因为我喜欢轻松开始)。但我不知道如何为接受实例化CompletionHandler。以下代码是错误的,我无法修复它:
package async
import java.nio.channels.AsynchronousServerSocketChannel
import java.net.InetAddress
import java.net.InetSocketAddress
import java.nio.channels.CompletionHandler
import java.nio.channels.AsynchronousSocketChannel
class AsyncServer (port: Int) {
val socketServer = AsynchronousServerSocketChannel.open();
socketServer.bind(new InetSocketAddress(port))
val connectionHandler = new CompletionHandler[AsynchronousSocketChannel, Integer](){
}
def init() = socketServer accept(1 , connectionHandler)
}