Forums Register Login

Case expressions on a switch statement

+Pie Number of slices to send: Send


output:



The above code example has confused me. I thought that case expressions can only be compile time constants. Is (byte)c+2 a compile time constant?
+Pie Number of slices to send: Send
Yes it is, since 'c' itself is a compile time constant declared with the 'final' keyword and initialized at the same time.
+Pie Number of slices to send: Send
I thought a compile time constant is one that is declared as a literal or a public static final field. I didnt know that an expression can result in a compile time constant.
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 759 times.
Similar Threads
Automatic typecasting
Legal arguments in switch case statements
Switch case Compiler error
Compile Time Constant
Switch- Case doubt in case expressions.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 21:47:52.