これはコンパイルして動作します:
public class Test {
public static int[] array;
public static void main(String[] args) {
int[] temp = {42};
array = temp;
}
}
これはしません:
public class Test {
public static int[] array;
public static void main(String[] args) {
array = {42};
}
}
どうしてこれなの?一時的なローカル変数を使用せずに、非ローカル変数に配列を割り当てるにはどうすればよいですか?