I don't understand all the subtleties of class loading, but I gather
from previous discussions here that it's good practice for Clojure to
provide a class loader and for Clojure code to use it in the absence
of a compelling reason not to. Use of Class.forName directly is (at
least mildly) discouraged.
To address both of those concerns, classForName-initialize.patch
(uploaded to the group and in-line below) changes RT.java to expose an
optional "initialize" flag for RT/classForName.
After the change, existing calls to RT/classForName will work as they
always have, but callers that need to ensure the class is initialized
are now able to.
--Steve
Index: src/jvm/clojure/lang/RT.java
===================================================================
--- src/jvm/clojure/lang/RT.java (revision 1080)
+++ src/jvm/clojure/lang/RT.java (working copy)
@@ -1510,10 +1510,15 @@
static public Class classForName(String name) throws
ClassNotFoundException{
- return Class.forName(name, false, baseLoader());
+ return classForName(name, false);
}
+static public Class classForName(String name, boolean initialize)
throws ClassNotFoundException{
+ return Class.forName(name, initialize, baseLoader());
+}
+
+
static public float aget(float[] xs, int i){
return xs[i];
}
Here are a couple of examples, in the strictly java world (java
programming language and vm) when you want initialize to be false.
The idiomatic use case being byte code analysis
* FindBugs
* Code obfuscators
In these cases you do not want the static block to execute.
Thanks
Bhaskar