It doesn't matter where you put the brackets in the main method?

I'm currently starting to learn Java, and I was looking for some code and saw the brackets in two different places.

These are the two ways I've seen:

public static void main(String[] args) {

public static void main(String args[]) {

Is one of these methods the correct formatting, or does it just depend on which programmer prefers?

+4
source share
4 answers

Technically, this is a matter of your preference. When defining arrays, both are legal.

However, there is an overwhelming tendency and standard to put brackets after the reference type, as in String[] args. Some code checking tools even consider using brackets differently as bad convention or code smell.

+9

Google Java:

, : String[] args, String args[].

.

+2

JLS:

[] , , .

. , C/++ Java.

+1

, String[] args String args[]. , , , , .

I personally always write String[] args, as it seems to me, you should see by type that it is an array. In addition, it is more consistent with String[] array = new String[count], since the brackets come with the type on the right side.

0
source

All Articles