While looking over a source file, i saw two ways of array initialization. I wonder is there a difference between
int[] value = new int[0];
and
int[] value_next = new int[]{};
?
Actually there is no difference. It's Syntactic sugar in java array declaration.
The first type declaration is less confusing, at least for me :).
Note: I'm not sure why you given the length as zero while declaring.
If possible, go through https://stackoverflow.com/a/19558179/1927832 for some advantages over another.
Now the proof (and an exercise):
Create two classes, each containing one declaration. Compile them to get .class files.
On each of the two created files, do:
javap -c yourClass
To see the bytecode.
Now you can answer your own question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With