I've tried to pass an initialization list {...} to a constructor and it didn't work.
When I instead declared it in a method local variable (int[]) it worked flawlessly.
Why is that?
public class QuickSort {
int[] a;
public QuickSort(int[] a) {
this.a = a;
}
public static void main(String[] args) {
// ###################
// ### WORKS ##
// ###################
int[] a = {8,12,79,12,50,44,8,0,7,289,1};
QuickSort sort = new QuickSort(a);
// ###################
// ### DOESN'T WORK ##
// ###################
//QuickSort sort = new QuickSort({8,12,79,12,50,44,8,0,7,289,1});
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…