Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top