如何将未检查的从整数转换为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);
    }

最佳答案

如果您知道要在Integer堆栈中存储undoStackIndexes索引,则不应使它与T类型通用:

SimpleStack<Integer> undoStackIndexes = new SimpleStack<Integer>();

08-18 18:22