That's how I read things. Importing a class causes the class to be loaded (via Class.forName()) so that it can be stored in the namespace's mappings. My impression from the commented out older code is that some prior incarnation of the code used class names instead of Class objects in some prior incarnation which would avoid the loading. Seems like importing could potentially defer loading till use (and loading could still be forced via Class.forName() if needed).
On Wednesday, October 23, 2013 9:00:28 AM UTC-5, Aaron Cohen wrote: > > So, is this a correct summary of the problem? > > "Importing a class in clojure causes static initializers to run. This > differs from Java where static initializers don't run until the first > 'initialization' (either the invocation of a constructor, or invocation of > a 'main' method) of a class. In some cases, this makes it impossible to > create the environment that java classes expect to be present before they > are initialized." > > On Tuesday, October 22, 2013, Zach Oakes wrote: > >> Here's the error I get when I import LibGDX's Timer class: >> >> http://pastebin.com/q7wys8yi >> >> On Tuesday, October 22, 2013 9:55:16 PM UTC-4, Alex Miller wrote: >>> >>> I'd love to see a stack trace when that happens (could even be triggered >>> by dumping stack in your static initializer if nothing else). >>> >>> On Saturday, October 12, 2013 3:17:50 AM UTC-5, Wujek Srujek wrote: >>>> >>>> So you are saying compilation is trying to instantiate class and run >>>> static initializers? This seems very backward, are you sure? >>>> >>>> >>>> On Sat, Oct 12, 2013 at 8:30 AM, Zach Oakes <zso...@gmail.com> wrote: >>>> >>>>> I should add, I am aware I can bring in a class dynamically with >>>>> Class/forName, and that is what I ended up doing for the Timer class. >>>>> However, this is not always practical, and sometimes is simply not an >>>>> option if aot-compilation is required. >>>>> >>>>> >>>>> On Saturday, October 12, 2013 2:28:38 AM UTC-4, Zach Oakes wrote: >>>>>> >>>>>> I recently learned that merely importing a Java class in Clojure >>>>>> causes static initializers to be run. Sometimes, this causes compilation >>>>>> errors, because they are written with the assumption that they will only >>>>>> be >>>>>> run during runtime. >>>>>> >>>>>> I ran into this just now while trying to make a simple Clojure game >>>>>> with LibGDX. After simply importing its Timer class, I began getting >>>>>> compilation errors. The stack trace shows it is due to a static >>>>>> initializer<https://github.com/libgdx/libgdx/blob/511b557c1a2d23bf8110a05b0ef54cc20b7f958d/gdx/src/com/badlogic/gdx/utils/Timer.java#L32>attempting >>>>>> to instantiate the class! >>>>>> >>>>>> I also ran into this recently while trying to use RoboVM. My question >>>>>> is, do I have any options? I haven't found many discussions about this >>>>>> here >>>>>> or elsewhere. This surprises me, because it seems like something more >>>>>> people should be running into. >>>>>> >>>>> -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.