So I have this bit of code:
public PacketListener packetListener;
@Override
protected void channelRead0(ChannelHandlerContext ctx, Packet<?> packet) throws Exception
{
if (this.channel.isOpen()) {
try {
packet.handle(this.packetListener);
}
catch (Exception ex) {
;
}
}
}
on packet.handle(this.packetListener);
I get the error: The method handle(capture#1-of ?) in the type Packet<capture#1-of ?> is not applicable for the arguments (PacketListener)
. What is wrong with this? I mean I know that the ? type is unknown and it usually disallows parameters of any type (or at least so I've read), but in the code the type argument extends PacketListener
so I don't see the error.
The Packet class looks like this:
public interface Packet<T extends PacketListener>
{
void encode(PacketDataSerializer packetdataserializer) throws IOException;
void decode(PacketDataSerializer packetdataserializer) throws IOException;
void handle (T listener);
}
And before assuming anything, no it's not Minecraft Server related, yes I helped myself with the naming and structure from the Minecraft Server source code (the one from bukkit/spigot servers).
EDIT:
Alright a comment got me thinking so I tested something and it's not a wildcard and it doesn't work...
private static <T extends PacketListener> void a(Packet<T> packet, PacketListener packetlistener) {
packet.handle(packetlistener);
}