Instantiating Non-static Nested Classes in Clojure

2009-07-08

In the interest of furthering Google’s ability to solve minor development issues, I should show what I recently learned by trial and error about Clojure’s syntax for instantiating Java’s inner classes. Java distinguishes between static nested classes and non-static nested classes, and the only information I could find on Clojure syntax only applied to the static nested classes, which incidentally are instantiated like this:

(new OuterClass$InnerClass)

Not too hard. Non-static classes on the other hand must be constructed on a member of the outer class. And so

(OuterClass$InnerClass. my-outer-class)

I assume appropriate arguments could be appended to either of those statements if the constructor required it.

Comments

There's some javascript trying to load some comments, and if you're reading this, it's probably not working.