Well, you wouldn't have. As the methods are static they are not part of
an instance, so the actual object would probably have only 16 bytes or
so. But your solution is obviously as good or even superior.
Best regards
Henning
John schrieb:
I wanted to avoid having multiple copies of the Utils class lying around
in memory, so I switched to using a singleton Utils class, that I can
instantiate and add to the Velocity context.
Thanks guys!
John
On 12/21/06, *Henning P. Schmiedehausen* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
John <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> writes:
Hi,
IIRC, you can add a public C'tor to construct a dummy object and then
use that in the context. I remember that something like this is the
reason why some of the Utility classes in Jakarta commons have a
public, no-arguments constructor even though the classes contain only
static methods.
A while ago, we talked about "invocation of static methods" but I'm
not sure if that discussion ever went anyplace.
Best regards
Henning
>------=_Part_26899_4319714.1166483090496
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>Content-Transfer-Encoding: 7bit
>Content-Disposition: inline
>Hi all,
>I'm getting familiarized with Velocity, and I'm wondering about
how I should
>handle the following case:
>I have a utility class called "Utils". Now typically if I wanted
to use the
>member functions in this class in my other Java classes I would
declare them
>static and reference them as so " Utils.checkInput(int)".
>Now with Velocity and the idea that if I want these utilities
available to
>the VTL, I understand I need to put the object in the
VelocityContext. From
>what I have seen (for example with the VelocityFormatter tool), a
new object
>is created and put in the context
>velocityContext.put("formatter", new VelocityFormatter());
>So my question is: what do I do with my Utils class? Should I
create a new
>instance as well? Does that mean I should change my static methods to
>non-static methods? I guess my inexperience is showing here :)
>Thanks!
>John
>------=_Part_26899_4319714.1166483090496--
--
Henning P. Schmiedehausen -- [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> | J2EE, Linux,
91054 Buckenhof, Germany -- +49 9131 506540 | Apache person
Open Source Consulting, Development, Design | Velocity - Turbine guy
"Save the cheerleader. Save the world."
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
--
Henning P. Schmiedehausen -- [EMAIL PROTECTED] | J2EE, Linux
91054 Buckenhof, Germany -- +49 9131 506540 | Apache person
Open Source Consulting, Development, Design | Velocity - Turbine
"Save the cheerleader. Save the world."
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]