Chapter 5.
p184. In a class, all the variables are initialized before any method can be called, even the constructor.
Array initialization and toString:
int[] a = new int[]{1,2,3,4};
int[] b = {1,2,3,4};
System.out.println(Arrays.toString(a));
@Test
public void test() {
int[] ints= {1,2,3,4};
print(1,2,3,4);
print(ints);
print();
}
private void print(int... args)
{
System.out.println(Arrays.toString(args));
for (int a : args) {
System.out.println(a);
}
}
Variable argument list makes method overloading more complicated. You should generally only use a variable argument list on one version of an overload method. Or consider not doing it at all.
.
The only safe methods to call inside a constructor are those that are final in the base class.