1
\$\begingroup\$

Here is a reference to how switch statements should be formatted (I've never seen this used at the two companies I've worked at):

enter image description here

And a contradictory one, which I am partial to (and is IntelliJ IDEA default):

enter image description here

The obvious discrepancy is in the tabbing of the case statement - whether it's

switch(case) {
case x:
}

or

switch(case) {
  case x:
}

Is there a right or wrong one?

\$\endgroup\$
4
  • 2
    \$\begingroup\$ This post isn't really suited for Code Review (because you're not asking us to review code). It would be better off on Stackoverflow, but would probably get closed there too as it is opinion based. Indeed, Oracle did not make a Mistake here, it's just a different code style. \$\endgroup\$
    – Marv
    Mar 15, 2021 at 17:40
  • \$\begingroup\$ correct me if im wrong, but if their documentation says, quite literally, that a particular command should "have the following form", doesn't that mean they are making a statement of fact as to java syntax? I'm just trying to ascertain that because the first example doesn't look right to me \$\endgroup\$
    – notacorn
    Mar 15, 2021 at 18:40
  • 2
    \$\begingroup\$ The document you are reading is not a syntax guide, it is about code conventions or code style. Both examples are syntactically correct and either might be correct style depending on which conventions you adhere to. And by the way, the document you linked is wildly outdated: "The last revision to this document was made on April 20, 1999" \$\endgroup\$
    – Marv
    Mar 15, 2021 at 18:55
  • 1
    \$\begingroup\$ Of course, SunSoft is right and everyone even mentioning the possibility of deviating a heretic. (Where do you suggest to place loop labels?) \$\endgroup\$
    – greybeard
    Mar 15, 2021 at 21:26

0

Browse other questions tagged or ask your own question.