如何修复从Integer到T的未经检查的强制转换?我在这行中得到了这个警告:
undoStackIndexes.push((T)index);
代码:
SimpleStack<T> undoStackIndexes = new SimpleStack<T>();
SimpleStack<T> undoStackDatas = new SimpleStack<T>();
public void add( int idx, T x ){
Node<T> p = getNode( idx, 0, size( ) );
Node<T> newNode = new Node<T>( x, p.prev, p );
newNode.prev.next = newNode;
p.prev = newNode;
theSize++;
modCount++;
undoStackDatas.push(newNode.data);
Integer index = new Integer(idx);
undoStackIndexes.push((T)index);
}
答案 0 :(得分:2)
如果您知道要在Integer
堆栈中存储undoStackIndexes
索引,则不应使用T
类型将其设为通用:
SimpleStack<Integer> undoStackIndexes = new SimpleStack<Integer>();