I call the java method from io.netty.bootstrap.BootStrap, which has the following signature:
public <T> B option(ChannelOption<T> option, T value)
I use the following code to call this method:
b.option(ChannelOption.SO_KEEPALIVE, true);
And this does not compile with the following error:
Error:(57, 30) type mismatch;
found : io.netty.channel.ChannelOption[Boolean]
required: io.netty.channel.ChannelOption[Any]
Note: Boolean <: Any, but Java-defined class ChannelOption is invariant in type T.
You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
b.option(ChannelOption.SO_KEEPALIVE, true); // (4)
^
I don’t quite understand what this says, but I understand that it is complaining about getting a boolean, since it was parameterized
Anyinstead Boolean. So I tried the following code and it works:
b.option(ChannelOption.SO_KEEPALIVE, Boolean.box(true));
This compiles and works. Is there any way to make it more beautiful without calling box?
Can anyone translate this compiler error?
Thank.
simao source
share