簡體   English   中英

類型安全性:未經檢查的從整數到T的轉換

[英]Type safety: Unchecked cast from Integer to T

如何將未檢查的從整數轉換為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>();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM