Are these two arrays identical in form? (They seem to be when tested.) If yes, then why are they both permitted? Is one purely for backward compatibility? Which is best practice?
public static void main(String[] args)
{
Auto[] array0 = new Auto[] { new Auto(6, "Lemons"),
new Auto(4, "Rusty")
};
Auto[] array1 = { new Auto(5, "German"),
new Auto(8, "Detroit")
};
}
The latter can only be used to initialize an array when you are declaring it.
For example, suppose you have the following method:
In this case, you could do
foo( new Auto[] { new Auto(6, "Lemons") }), but notfoo( { new Auto(6, "Lemons") }).