I had a problem creating some arrays.
Here is the code
Predicate<Integer[]>[] endOfLine = {
curPoint -> curPoint[0]==r2,
curPoint -> curPoint[0]==c2,
curPoint -> curPoint[0]==r1,
curPoint -> curPoint[0]==c1
};
Consumer<Integer[]>[] move = {
curPoint -> { curPoint[0]++; },
curPoint -> { curPoint[1]++; },
curPoint -> { curPoint[0]--; },
curPoint -> { curPoint[1]--; }
};
and eclipse (maybe compiler?) said:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot create a generic array of Predicate<Integer[]>
I Googled, and found that generic type parameter array can't be made in Java.
I read about compile time and runtime, and I thought it may be not my problem.
I saw some code which compile compiled:
List<Integer>[] arrayOfLists = new ArrayList[2];
ArrayList<Integer[]> lists =new ArrayList<>();
ArrayList<Consumer []> [] lists = new ArrayList[5];
Predicate<Integer[]>[] p = new Predicate[5];
p[0] = a -> a[0] == 0;
Predicate<Integer[]>[] pp = { a -> a[0] == 0 }; //cant be compile
and I read oracle doc and found this:
"Cannot Create Arrays of Parameterized Types"
I concluded my shortcut syntax, {} is the problem. Shortcut syntax create code with parameterized type. Is this correct?