commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@centras.lt>
Subject Re: StringUtils constructor is private
Date Mon, 12 Aug 2002 22:28:44 GMT
Hi,
we can add "ReflectUtils" to instantiate objects with private contructor,
something like
this :

Object newInstance(Class clasz){
 try{
       Constructor constructor = clasz.getDeclaredConstructor( new Class[]
{});
       constructor.setAccessible(true);
       return constructor.newInstance( new Object[]{});
..............................................................


----- Original Message -----
From: "Craig R. McClanahan" <craigmcc@apache.org>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Cc: <steven@caswell.name>
Sent: Tuesday, August 13, 2002 12:15 AM
Subject: Re: StringUtils constructor is private


>
>
> On 12 Aug 2002, Daniel Rall wrote:
>
> > Date: 12 Aug 2002 14:30:59 -0700
> > From: Daniel Rall <dlr@finemaltcoding.com>
> > Reply-To: Jakarta Commons Developers List
<commons-dev@jakarta.apache.org>
> > To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> > Cc: steven@caswell.name
> > Subject: Re: StringUtils constructor is private
> >
> > "Steven Caswell" <steven@caswell.name> writes:
> >
> > > I was under the impression that Velocity could not invoke static
> > > methods. If this is true, then creating an instance of StringUtils
would
> > > not do any good. Hence I am -1 on putting in a public constructor
since
> > > it is generally good practice to prevent construction of an instance
of
> > > a class that has no member methods.
> >
> > Velocity will invoke static methods on an instance, just as Java will.
> >
>
> But Velocity apparently *requires* an instance in order to do this,
> whereas Java doesn't.
>
> Call it a restriction instead of a flaw if you want; it's a requirement
> imposed by Velocity on classes whose static methods it wants to access.
>
> Craig
>
>
>
> > --
> > To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message