I have used this before so I have NO idea why this doesn't work. Consider this code
public class NioServer implements Runnable {
private EventLoopGroup group;
private ServerBootstrap b;
public static final AttributeKey<Session> SESSION_KEY = new AttributeKey<>("SessionHandler.attr");
@Override
public void run() {
group = new NioEventLoopGroup();
b = new ServerBootstrap();
b.group(group)
.channel(NioServerSocketChannel.class)
.localAddress(435)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("Session Handler", new SessionHandler());
}
});
}
}
The AttributeKey SESSION_KEY does not want to work and gives the error:
"cannot infer type arguments for AttributeKey<> reason: cannot infer type-variable(s) T (actual and formal argument lists differ in length) where T is a type-variable: T extends Object declared in class AttributeKey"
I don't get it... Am I missing something? There are no other questions about this however other questions do successfully use AttributeKey in this way.
Specs:
Update:
Alright so I have downgraded the version to 4.0.21 Final
and apparently AttributeKey<>("")
is deprecated however I cannot find any further information on this. Anyone knows the replacement/alternative for this in the 4.1.0
version? It works in 4.0.21 Final
by the way.
Alright. Quoting the user 'Mics':
Short answer: There's no AttributeKey(String) in netty 4.1, use AttributeKey.valueOf(String). Additional information: github.com/netty/netty/issues/1824
Thanks for the answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.