ArrayListを拡張してmapを作る
http://d.hatena.ne.jp/kaiseh/20090225/1235560788
から始まったこのあたり。
もはや内部イテレータでもなんでも無いのかも。
それすらわからなくて混乱中。で、タイムリミット
私の頭の中だけは前のエントリの続き。。。
package mapp; import java.util.*; //publicに変更時はファイル切り分け必要! interface mapProcedure<E> { boolean process(E o); } public class ArrayListie extends ArrayList{ public ArrayListie() { super(); } public ArrayListie(Collection c) { super(c) ; } public ArrayListie(int i) { super(i) ; } public ArrayList map(mapProcedure proc){ ArrayList r_ = new ArrayList(); for(int i= 0,len = super.size();i < len;i++){ if(proc.process(super.indexOf(i))){ r_.add(super.indexOf(i)); } } return r_; } public static void main(String[] args){ ArrayListie ar = new ArrayListie(); for(int i=0;i < 10;i++){ ar.add(i); } mapProcedure<Integer> proc_ = new mapProcedure<Integer>() { public boolean process(Integer o) { if(o > 3){ return true; } return false; } }; //ArrayList<Object> maped = ar.map(proc_);//=>まぁ動く //無理矢理キャストかかってる状態? //中身が違うものがかえってくるバージョンで実験が必要だけどめんどい。 ArrayList<Integer> maped = ar.map(proc_); //出力して確認!というか拡張for文練習 for(Object o : maped){ System.out.println("ArrayListie:" + ((Integer)o).toString()); } } }
書いたしテストmainは動くのだけれど
mapProcedure<Integer> proc_ = new mapProcedure<Integer>() { public boolean process(Integer o) { if(o > 3){ return true; } return false; } };
がなにやってるのかわからん。
interfaceって実体持てないんですよね?
implementsしないといみないんですよね?
この文の右辺がmapProcedureの型ってことにならないと代入はできねぇしなぁ。。
はぁ、javaわかんね。