This technique was also proposed in the JDC tech tip of this month, and has the caveat that a serialized/deserialized String would not work with ==, even if it was assigned from a static value.
OTOH, the final code translated for a switch depend on the number of 'case' values. If they're many the compiler should use some kind of binary search (as a quick sort, but for finding) previously ordering the values. That is why they are required to be primitive types. When the options are a few, they're searched lineally to improve performance. Or it was so the last time I poke around that. > -----Mensaje original----- > De: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]En nombre de > [EMAIL PROTECTED] > Enviado el: jueves, 07 de febrero de 2002 18:44 > Para: [EMAIL PROTECTED] > Asunto: RE: [JBoss-dev] so how fast is string comparison > > > Most of the strings we are talking about are dynamic (or at least run-time > configurable), so we would have to do string.intern() to be able to use == > and I don't think that you'd want that internal list of strings > growing like > that. Besides, when you have a new string and do an intern(), it looks up > the common string in a hashtable using hashcode to return the string on > which you can do == on. > > Michael > > -----Original Message----- > From: Adam Heath [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 07, 2002 1:17 PM > To: marc fleury > Cc: Jboss-Development@Lists. Sourceforge. Net > Subject: Re: [JBoss-dev] so how fast is string comparison > > > On Thu, 7 Feb 2002, marc fleury wrote: > > > when we do > > > > if (string.equals("this")) > > > > else if (string.equals("that")) > > > > how much slower is it than > > > > switch (stringAsInt) > > case THIS: > > > > case THAT: > > If strings are final, then you can use ==, instead of the much slower > .equals(). > > A switch stmt is really nothing more than a series of if/elseif > blocks. So, > making all strings static/final, and using ==, should make for a win, > without > making the code hard to read by using abstract ints. > > > > _______________________________________________ > Jboss-development mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > > _______________________________________________ > Jboss-development mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > > _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development