first active use of a class

Jim Van Peursem Jim_Van_Peursem-FJV100@email.mot.com
Thu Apr 8 15:00:00 GMT 1999


>>>>> "Godmar" == Godmar Back <gback@cs.utah.edu> writes:

Godmar> I think he said that the way to bend the rules is to create
Godmar> "active uses" before invoking main(). The JLS spec supposedly
Godmar> leaves open what is done before main(). Hence, one could
Godmar> insert code that uses non-constant static fields. Or, you
Godmar> could have your JNI driver first invoke a Class.forName(,
Godmar> true) for all classes you're interested in before it invokes
Godmar> main().
Yikes. That's not safe. Some developers rely on static initializers,
and this specified behavior of "immediately before" to manage resource
allocation "just in time". This could cause problems if all static
initializers were blindly run at launch time. For example, what if I
had two classes that were designed to be used individually, based on
information only available through discovery at runtime. If each class
was designed to assume that it was going to be run exclusively of the
other (based on the specified behavior of the jls), running static
initialization on both at launch time would cause problems.
On the other extreme, having no initialization except through a JNI
driver (which is an interesting idea) means extra work for the
developer to deploy this solution on your platform -vs- others.
-jvp


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /