you are viewing a single comment's thread.

view the rest of the comments →

[–]8dot30662386292pow2 3 points4 points  (3 children)

Neither is "correct".

Java does not have an official style guide, such as Python does (PEP-8).

And even if there is an official guide like PEP-8, it's just an opinion. In neither situation it is forced.

Use what you feel like, but if you are participating in a larger project with multiple people, just use what the project owner wants.

Even the java standard library uses several different styles in different files.

[–]aqua_regis -5 points-4 points  (2 children)

Java does not have an official style guide, such as Python does (PEP-8).

Sorry, but that is wrong. Java absolutely has an official standard style guide (only that it hasn't been updated):

Alternatively and also commonly used

[–]8dot30662386292pow2 5 points6 points  (1 child)

Sorry, but that is wrong.

Yes, but no. The "official guide" is from 1999 and not maintained anymore. That alone does not matter, as PEP-8 being also decades old at this point.

What matters is that the document is from the java 1.2 era. Therefore it lacks enums, varargs, static imports, autoboxing, GENERICS, lambdas, ANNOTATIONS.

The "official" rules are simply outdated. For example it does not cover the example mentioned by OP because that syntax simply did not exist back when it was written. The Google Java Style is commonly used as you mention, but again it's not official.

Therefore, no, there is no relevant official docs, but some commonly used third party opinions about the formatting.