You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kamholz, Keith (corp-staff) USX" <kk...@moog.com> on 2003/06/05 17:05:43 UTC
switch statement
Hey everyone,
This is more of a Java question than a Struts question, I hope you all don't
mind.
I'm just wondering if there is any way to use a String for a switch
statement, or if you are restricted to the true primitive types.
I haven't found a way, but it seems like something that lots of people would
want that wouldn't be hard for the Java developers to allow for.
Wouldn't you agree?
Keith Kamholz
Programming and Architecture
Moog Inc.
Phone: (716) 687-7001
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: switch statement
Posted by Erik Price <ep...@ptc.com>.
Kamholz, Keith (corp-staff) USX wrote:
> Hey everyone,
> This is more of a Java question than a Struts question, I hope you all don't
> mind.
Not really, but for future reference I have found this resource to be
more helpful for such questions:
http://forum.java.sun.com/forum.jsp?forum=31
> I'm just wondering if there is any way to use a String for a switch
> statement, or if you are restricted to the true primitive types.
> I haven't found a way, but it seems like something that lots of people would
> want that wouldn't be hard for the Java developers to allow for.
> Wouldn't you agree?
The reason why it doesn't work is probably specific to the
implementation of the language (maybe performance reasons), but a lot of
people don't miss it -- nor would they agree, I suspect. The reason is
that you can usually add behaviors to objects so that a single
polymorphic method call can usually eliminate all of the infrastructural
work of writing a switch statement, so doing a switch on an object
doens't make much sense in that context. Of course, this is not
applicable in all senses, such as your case with String which is final....
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org