- 773 名前:デフォルトの名無しさん mailto:sage [2008/07/01(火) 02:43:47 ]
- イテレータとコレクションに関する質問です.
クラスHogeCollectionはgetFoos()でiteratorを返すのですが, HogeCollection h = new HogeCollection(); h.add( new Foo() ); for(Iterator<Foo> it = h.getFoos(); it.hasNext(); ){ Foo f = it.next(); } h.getFoo()の部分で "型の安全性:型Iteratorの式は、未検査の型変換を使用して Iterator<Foo>に準拠するようにする必要があります。" という警告がでます. かといって HogeCollection<Foo> h = new HogeCollection<Foo>(); とすると "型HogeCollectionは総称ではありません。引数<Foo>でパラメータ化できません。" とエラーになります. LinkedList<E>クラスのときはできました. LinkedList<Integer> l = new LinkedList<Integer>(); l.add(1); for (Iterator<Integer> it = l.iterator(); it.hasNext();) System.out.println(it.next()); HogeCollectionの場合,どうすれば正しい構文になるのでしょうか. Eclipse, JavaSE6です.
|

|