Is it possible to execute code when a class is loaded from a package?
Like a sort of static constructor?

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
Yoyoma_2 - 15 Apr 2004 19:35 GMT
> Is it possible to execute code when a class is loaded from a package?
> Like a sort of static constructor?
You mean you have a Class myClass and you want to execute it?
you just have to do Object instance = myClass.newInstance();
Bryce (Work) - 15 Apr 2004 19:41 GMT
>Is it possible to execute code when a class is loaded from a package?
>Like a sort of static constructor?
Yep. Static initializers.
class Something {
static {
// code here will execute when class is first loaded
}
}
--
now with more cowbell
Josef Garvi - 15 Apr 2004 19:46 GMT
> Yep. Static initializers.
>
[quoted text clipped - 3 lines]
> }
> }
Thanks.

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
Dale King - 15 Apr 2004 19:44 GMT
> Is it possible to execute code when a class is loaded from a package?
> Like a sort of static constructor?
Yes. You are referring to a static initializer. It looks like this:
class MyClass
{
static
{
System.out.println( "Called when class is loaded" );
}
}
--
Dale King
Blog: http://nobleware.homedns.org/Blog
Roedy Green - 15 Apr 2004 22:24 GMT
>Is it possible to execute code when a class is loaded from a package?
>Like a sort of static constructor?
see http://mindprod.com/jgloss/initialisation.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.