我的代码中有错误。
我有这两个清单:
public static final List<Class<? extends Packet>> OUT_PACKETS = Arrays.asList(PacketPing.class);
public static final List<Class<? extends Packet>> IN_PACKETS = Arrays.asList(PacketPing.class);
但是如果我尝试将PacketPing类添加到此列表中,则会将其标记为红色。但为什么呢?
这是我的Packet.class:
public interface Packet {
public void read(ByteBuf byteBuf) throws IOException;
public void write(ByteBuf byteBuf) throws IOException;
}
这是我的PacketPing.class:
public class PacketPing implements Packet {
private long time;
public PacketPing(){ }
public PacketPing(long time){ this.time = time; }
@Override
public void read(ByteBuf byteBuf) throws IOException {
this.time = byteBuf.readLong();
}
@Override
public void write(ByteBuf byteBuf) throws IOException {
byteBuf.writeLong(this.time);
}
public long getTime() { return time; }
}
提前致谢!
编辑: 这就是我的IDE所说的,但没有任何可行的...... Link to the screenshot
我使用Java 8
答案 0 :(得分:1)
如果您使用java7:
,请将其更改为此特定方式public static final List<Class<? extends Packet>> OUT_PACKETS = Arrays.<Class<? extends Packet>>asList(PacketPing.class);
在java8中,您的声明是正确的,并且编译正确