Also, every time you reference a String literal, an object is created.
Using the static constant avoids this. Just good practice.
Saving the creation of a couple of objects is moot, but on large
projects on stressed servers, every little bit counts.
Scott Barr
www.exergonic.com.au
On Mon, 2003-03-10 at 12:50, Paul Linden wrote:
> Dan Allen wrote:
>
> >I have seen this used in several places and I have to ask, why? Ted
> >Husted uses it in Scaffold and there are several examples around the
> >web that use it as well. What am I talking about?
> >
> >consider this short code snippet
> >
> > return mapping.findForward(Tokens.SUCCESS_KEY);
> >
> >How is that any different than
> >
> > return mapping.findForward("success");
> >
> >Both are in english, one just resolves to a variable the other is
> >static. I guess I could understand the use of tokens for placing
> >keys into the request scope since you might one day find you have a
> >conflict, but besides that, what is the purpose?
> >
> >Dan
> >
> >
> >
> You should always use static constants when referencing Strings that are
> used in more than one place - if you had "sucess", your program would
> compile ok, but you would get a runtime exception when your action is
> accessed and Struts looked for the mapping for "sucess" - possibly after
> deployment if your test coverage is inadequate, but at the earliest once
> you've dropped your app into your webapps directory. If you have
> Tokens.SUCESS_KEY, your program wouldn't compile and you could fix the
> error immediately.
>
> Paul
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>