- This topic has 5 replies, 2 voices, and was last updated 17 years, 10 months ago by Riyad Kalla.
-
AuthorPosts
-
jierynMemberI’m seeing a formatting error when ‘return’ is used within a switch statement. The next line, if it is a comment, is erroneously indented to the next level. Please find the smallest amount of code to demonstrate:
public class SwitchTest { public static void main(String[] args) { final int a = 1; switch (a) { /* indentation */ case 1: return; // <-- notice the return /* indentation */ default: break; } final int b = 2; switch (a) { /* indentation */ case 1: break; // <-- notice the break /* indentation */ default: return; } } }
Thanks!
MyEclipse++
Riyad KallaMemberMoving to OT > Soft Dev
I’m not sure I follow, everything under a case should be indented as content of that case statement (like an implied body). This code looks OK to me… maybe I’m missing something?
jierynMemberIn switch #1 the comment on top of the default case is indented at a different level than the word ‘default’. However, in the second switch the indentation is at the same level as the word ‘default’. The only difference between the two switches is that in switch #1 the first case has ‘return’ instead of ‘break’; whereas, the second switch, which properly indents the comment on top of the 2nd case, default, uses a ‘break’ in the case statement above.
I realize my description is a bit confusing. This is best summarized by ‘return’ vs ‘break’ causes different indentation of comments on subsequent case statements.. ‘return’ screws up the comment, whereas ‘break’ handles it properly.
Hope this helps,
MyEclipse++ 🙂
Riyad KallaMemberThe indents all look the same to me in what you pasted… maybe I’m just not seeing it… please point out what I’m missing (I think I have my ‘dense as a rock’ hat on today or something…)
Attachments:
You must be logged in to view attached files.
jierynMemberPlease place your magic red tape around the /* */ comment areas. I’m sorry if I misled you, I am concerned about the indentation of the comments. It is inconsistent depending on whether I break vs return on the previous case statement.
Riyad KallaMemberOH! I knew I was missing something, I see exactly what you mean now.
-
AuthorPosts