Why does Jalopy format my Java code this way?

1k views Asked by At

When I type an entry for an array in java this way, Jalopy (an alternate program to Jindent) switches the square bracket to the other side. Am I typing the wrong way or what?

Before formatting:

Before

After formatting:

After

3

There are 3 answers

0
Naved On BEST ANSWER

Using square bracket after variable name is old style of C,C++. While placing it with the type name is recommended by Java. It is specific to java code style. Since Jalopy is specifically there to format java Code it uses recommended Java style to format. and Hence the code is changing.

1
Joey On

Consistency for one, I guess.

And more importantly to make the types clearer. Java (similar to C, I think) allows the [] to appear after either the type or identifier (or even both, being the equivalent of [][]). Putting them after the type makes very clear what the actual type is, because nickFreq is an int[], not an int.

0
fernando On

If you prefer the old C-style, you can configure it in your settings, see here:

http://www.triemax.com/products/jalopy/manual/java.html#ARRAY_BRACKETS_AFTER_IDENT

It gets quite interessting when it comes to multi-dimensional arrays...