Agreed. I use static a fair bit, but only within a very focused idiom:

All class variables are final, public or private depending on usage.
All methods are stand-alone, though they may sit on top of another one.

ie) StringUtils.capitalize(String) or UserProcedures.loadUser(int userId)

Other than that the only place I've found for static is the quick
'singleton' hack, and even then it's rare to find a getInstance worth the
effort.

Incidentally, I discovered the other day that 'int.class' is equivalent to
Integer.TYPE or some such. I hadn't realised you could do
<primitive>.class, so though I'd pass it on. Might help people using code
generators etc :)

Hen

On Thu, 1 Jan 2004, Michael Silverstein wrote:

> The suggested solution requires that the developer hard-code the name of
> the class in the method, which sort of defeats the purpose.
>
> As far as I know there is no way for a static method to dynamically
> determine the class in which it is running, and certainly none that
> would be considered 'neat and elegant'.
>
> I went down this path once, and decided to stay as far away from Java's
> static methods as possible. Static methods don't even support
> polymorphism.
>
> If you need global access to behavior try using singletons. If you want
> an intelligent implementation of class-side methods (and objects in
> general) use Smalltalk.
>
> -----------------------------
> Mike Silverstein
> SilverMark, Inc.
> The Object Testing Company
> www.silvermark.com
> **********************************
> * Providers of the "Test Mentor" *
> * family of testing tools        *
> **********************************
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Michael E. Mercer
> > Sent: Thursday, January 01, 2004 11:14 AM
> > To: Research Triangle Java User's Group mailing list.
> > Subject: Re: [Juglist] static reference to Class
> >
> >
> > MyClassName.class
> >
> >
> >
> > On Thu, 2004-01-01 at 11:09, Richard O. Hammer wrote:
> > > I have a class in which all the members are static.  Within these
> > > static members I want to get a handle to the Class.  What
> > is the best
> > > way to do that?
> > >
> > > Now, I know I could construct an instance of the class, and then say
> > > getClass() on that instance, but that seems unnecessarily
> > roundabout.
> > >   And I suppose I could say Class.forName("MyClassName")
> > but that is a
> > > little short of elegant, and if later I change MyClassName using
> > > Eclipse's neat renaming power, Eclipse won't change the string
> > > parameter "MyClassName" and I will be plagued with more work to do.
> > >
> > > So I want the neat and elegant way to learn the name of the
> > containing
> > > class from within a static method.  It there such?
> > >
> > > Thank you,
> > > Rich
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.545 / Virus Database: 339 - Release Date: 11/27/2003
>
>
>
> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>


_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to