Re: Why can't switch be used for objects



Bruce Wood <brucewood@xxxxxxxxxx> wrote:
> 1. Because it would be grossly slow.
> 2. Because the semantics of comparison are unclear (do you use equality
> by reference, or use the Equals method, or do you allow IComparers,
> or... ?)
> 3. Because if you need this then there is probably some other (cleaner)
> way to do what you want to do... which is why I'm wondering exactly
> where you need this switch statement and for what, in order to propose
> an alternate design. :-)

Actually, it's not entirely unreasonable, nor does it need to be slow -
with some extra support.

I've recently been playing around with Java 1.5's enums, which allow
switching and all kinds of fun. They're much more powerful than the
..NET enums - although there are certain bits of behaviour from .NET's
"simple" enums which Java makes slightly harder.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Scala
    ... durch das Hinzufuegen von Enums zu den primitiven Typen als erlaubte ... sealed trait AndOrEnum extends Function2[Boolean, Boolean, Boolean] ... Steuerungskonstrukt wie in Java.) ...
    (de.comp.lang.java)
  • Re: Why Generics?
    ... > Enums were truly needed. ... > There's a C# feature that I also think is desperately needed in Java. ... A syntax change doesn't help much here. ...
    (comp.lang.java.programmer)
  • Re: Why default parameter values where not included in Java
    ... >>to find what you're looking for then the following Java overloaded ... >>int ShowMessage(string MainMsg, string Title, int MessageType, int ... > can be achieved with method overloading, and method overloading was going to ... It's fun to read why the didn't include enums. ...
    (comp.lang.java.programmer)
  • Re: XML parsing with Java
    ... We found this out after writing a few thousand lines with generics, enums, and a few other 1.5 features. ... If I had the ears of the decision makers where I work, I'd suggest to them that the risk of continuing with Java 1.4, with its insufficient concurrent memory model and slower performance than modern versions, exceeds that of the conversion to Java 5, especially in our environment which involves multiple nodes with multiple processors running multiple JVMs with various forms of communication between them processing high peak volumes of information per unit of time under tight time constraints and rigorous availability requirements. ... The fear of upgrade that I've witnessed was based on considerations of product reliability on a new platform, cost of code conversions, and operations costs associated with migration to and maintenance of the new enterprise platform. ...
    (comp.lang.java.programmer)
  • Re: compare with empty string uses equals method or == ??
    ... > int for a somewhat safe usage, as a compromise in absence of enums. ... Sun Certified Developer for the Java 2 Platform ...
    (comp.lang.java.programmer)