我不是一名java开发人员,但我想在这部分代码中修复项目中唯一的警告:
public abstract class SelectorThread<T extends MMOConnection<T, RP, SP>, RP extends ReceivablePacket<T, RP, SP>, SP extends SendablePacket<T, RP, SP>>
{
protected static final Log _log = new MMOLogger(SelectorThread.class, 1000);
private final AcceptorThread<T, RP, SP> _acceptorThread;
private final ReadWriteThread<T, RP, SP>[] _readWriteThreads;
protected SelectorThread(SelectorConfig sc, IPacketHandler<T, RP, SP> packetHandler) throws IOException
{
_acceptorThread = new AcceptorThread<T, RP, SP>("AcceptorThread", this, sc);
_readWriteThreads = new ReadWriteThread[sc.getSelectorThreadCount()];
for (int i = 0; i < _readWriteThreads.length; i++)
_readWriteThreads[i] = new ReadWriteThread<T, RP, SP>("ReadWriteThread-" + (i + 1), this, sc, packetHandler);
}
...
}
警告:
Type safety: The expression of type ReadWriteThread[] needs unchecked
conversion to conform to ReadWriteThread<T,RP,SP>[]
拜托,有人可以帮我解决这个问题,或者告诉我必须知道解决这个问题。我理解上面的行是由<T, RP, SP>
修复的,但这不适用于数组。
更新:我看到我的问题是重复的,我的问题是:在数组中使用泛型是不安全的。但是,我如何更改代码来修复此问题?我所有的一切都是
_readWriteThreads = (ReadWriteThread<T, RP, SP>[]) Array.newInstance(ReadWriteThread.class, sc.getSelectorThreadCount());
但是这段代码也给了我一个警告。
答案 0 :(得分:0)
你可以添加注释@SuppressWarnings(“unchecked”)