[英]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.