Hello group,
Is there a way to simulate the C enum type without Java 1.5 such that
i can use it in a switch case?
Thanks for your reply
-AJ
1. [Switch()...case]From String to enum - Java
2. compiler oddity with switch/case & enum ...
I program in C for work (mostly embedded) and over time I adopted placing parenthesis around case statement constants to make them easier to read in the days before nice editors with syntax coloring (that is, "case (...):", where "..." represents the constant). Anyway, I also use Java a lot for writing simulations for testing the embedded software. So my writing style doesn't really change rather I am writing in C or Java and I've never had a compiler complain about parenthesis in a case statement. That is, until Java introduced enums. This seems odd to me that the compiler would throw an error because the enumerated value in a case statement is surrounded by parenthesis and not be concerned if a value that is not an enumerated value is surrounded by parenthesis. Usually, extra parenthesis (which is what I am introducing for the purpose of making the software easier to read) are ignored by compilers (as long as they match up, that is, an opening and closing parenthesis exist). Give it a try, frankly I think this a compiler error. Especially, given the errors you get if you try it. They are: "an enum switch case label must be the unqualified name of an enumeration constant" and "duplicate case label" These errors are more indicative of the error that occurs if you qualify the enum value. Worthy of posting as an error to Sun?
Given the following (bunch of stuff missing for clarity):
---------------------------------------
enum Foo
{
ONE, TWO;
}
...
switch(getFoo())
{
default:
ONE:
doOne();
break;
TWO:
doTwo();
break;
}
---------------------------------------
If getFoo() returns a null, then an exception occurs.
Should not the default case be processed? It should be the equivalent
of a "not found" value, I would think.
--
Wojtek :-)
5. switch or select case and code inside it
mo wrote:
> Hi,
>
> I have this code:
>
> var var1 = eval(Request("Page"));
Warning: tautological use of eval
var var1 = Request("Page");
suggested.
> Response.Write(">>"+var1);
Warning: unescaped HTML
Response.Write(">>"+var1);
suggested.
> switch(var1)
> {
> case "Monthly":Response.Write("Monthly<BR>") %>
Error: unterminated switch statement caused by return to HTML
Move %> to after:
> }
suggested.
<snip>
Hope it helps - you just know I havn't got ASP running :)
Dom
8. Switch..Case Statement Question.
Can someone tell me if the following Switch...Case construct is valid?
I'm wanting to check for multiple values in the Case statement without
explicitly listing each values.
So for example, will case 1-35: work? If this would work, will it
consider all numbers between 1 and 35 inclusive of 1 and 35? Please let
me know if the following will work below:
switch(state){
case 1-35:
case 37:
do something_1;
break;
case 36:
do something_2;
break;
case 38-50:
do something_3;
break;
}
Thank you.
Andy.