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

 -  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)



Bo
May.18, 2001


Reply via email to