That's what I thought, too. I guess I'll have to leave my initialization
code inside the static blocks.
Right now, I'm only using these classes in one context, so the classloader
issues don't apply. (yet...)
Thanks Charlie and Bo!
--jeff
----- Original Message -----
From: "Cox, Charlie" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 18, 2001 11:21 AM
Subject: RE: Bean Choices (code question)
>
> >
> >-----Original Message-----
> >From: Bo Xu [mailto:[EMAIL PROTECTED]]
> >Sent: Friday, May 18, 2001 1:47 PM
> >To: [EMAIL PROTECTED]
> >Subject: Re: Bean Choices (code question)
> >
> >
> >Jeff Kilbride wrote:
> >
> >> Hi Charlie,
> >> [...]
> >> On the same subject, are class constructors called when static methods
> are
> >> accessed? Right now, in my "all static method" classes, I'm doing my
> >> initialization in static blocks. I'm wondering if I can move that
> >> initialization into the class constructor, but I'm not sure if/when the
> >> constructor is called when a static method is called.
> >>
> >> Any insight on this point, also, is greatly appreciated.
> >>
> >> Thanks,
> >> --jeff
> >> [...]
> >
> >Hi :-) I did a test, I find:
> >- when I invoke a static method with "className.methodName(...)",
> > constructor and non-static init-block will not be invoked
> >
>
> That's what I thought. The constructor is not invoked because there is no
> instance of the class. Basically, if it's not static, it won't/can't run
> until an instance is created. Therefore static methods can only call other
> static methods in the same class.
>
>
> > - it doesn't metter that if this class is a "all static method style
> class"
> > or Not, i.e., this class can have all of the following:
> > % static init-block/non-static init-block
> > % static field/non-static(instance) filed
> > % static method/non-static method
> >
> >- only when this class is being loaded into the classloader,
> > static init-block will be invoked(i.e., normally, static init-block
> > only will be invoked One time), now we only have a Class object
> > of my-class, we don't have the instance object of my-class.
> >
> >- I am not sure if the above is righ when Java Reflection is used to
> > find/load this class(like a Servlet container does)
> >
> I think this is where the classloader(s) issue comes into account and that
> separate instances in different contexts would be considered different
> classes. There was a very good explaination of tomcat's classloading
> discussed in a previous thread :
> http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg13260.html
>
> >
> >
> >Bo
> >May.18, 2001
> >
>
> Charlie
>