さまざまな理由から、リストを配列に変換したいのですが、コレクションにはジェネリックのオブジェクトが含まれています。generic型のコレクションを配列に安全に変換する方法は?
@supressWarnings( '未チェック')の注釈は必要ありませんが、コンパイルするために次の4つのオプションを試しましたが、いずれも機能しません。この問題を解決するソリューションはありますか、または注釈を使用する必要がありますか?
Iterator<T>[] iterators;
final Collection<Iterator<T>> initIterators = new ArrayList<Iterator<T>>();
// Type safety: Unchecked cast from Iterator[] to Iterator<T>[]
iterators = initIterators.<Iterator<T>>toArray(
(Iterator<T>[])new Iterator[initIterators.size()]);
// Type safety: Unchecked invocation toArray(Iterator[]) of the generic
// method toArray(T[]) of type Collection<Iterator<T>>
// Type safety: The expression of type Iterator[] needs unchecked conversion
// to conform to Iterator<T>[]
iterators = initIterators.<Iterator<T>>toArray(
new Iterator[initIterators.size()]);
// Type safety: The expression of type Iterator[] needs unchecked conversion
// to conform to Iterator<T>[]
iterators = initIterators.toArray(new Iterator[initIterators.size()]);
// Doesn't compile
iterators = initIterators.toArray(new Iterator<T>[initIterators.size()]);
多分[[This(http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ104)]少し助けてください。とにかく、なぜArrayList(ArrayList)の代わりにArray(ジェネリックをサポートしていない)を使用したいのか興味があります。 – Pshemo
[Array of Generic List](http://stackoverflow.com/questions/7810074/array-of-generic-list)の可能な複製。参照:[複数の子を持つツリーの配列の汎用型](http://stackoverflow.com/questions/15957325/generic-types-in-an-array-for-a-tree-with-more) - 1歳未満の子供)。 –
@PaulBelloraあなたがリストアップした質問は重複していないと思いますが、同様の内容について話します。 –