Reported by chouser, Jan 15, 2009
Describe the feature/change.
It's currently impossible to create a class with gen-class that calls
its own (or its super-classes') methods when it is constructed. This
is a problem if there is stateful initialization required by the
superclass for which it has only methods, not ctor args.
Was this discussed on the group? If so, please provide a link to the
discussion:
http:http:
Comment 1 by chouser, Mar 07, 2009
(No comment was entered for this change.)
gen-class-post-init.patch
3.7 KB Download
Comment 2 by cjkent, Mar 24, 2009
I've applied the patch and it works, but only if I define a post-init function with
no args. I was expecting at least a single "this" arg. Or is there another way to
get a reference to the newly created object?
Comment 3 by chouser, Mar 24, 2009
The args given to your class's constructor are passed directly to your post-init
function. But you have a good point -- the 'this' arg should probably be included.
I've attached a new patch that allows this:
(ns clojure.contrib.test-clojure.gen-class
(:gen-class
:extends javax.swing.border.TitledBorder
:constructors {[int int String] [String]}
:init my-init
:post-init after-ctor))
(defn -my-init [x y s]
(println "Init ignoring" x "and" y ", going with" (str "foo+" s))
[[(str "foo+" s)] nil])
(defn -after-ctor [this x y s]
(print "Constructing" this "with ")
(prn x y s))
user=> (compile 'clojure.contrib.test-clojure.gen-class)
clojure.contrib.test-clojure.gen-class
user=> (clojure.contrib.test_clojure.gen_class. 3 4 "hello")
Init ignoring 3 and 4 , going with foo+hello
Constructing #<gen_class clojure.contrib.test_clojure.gen_class@1ab2b55> with 3 4 "hello"
#<gen_class clojure.contrib.test_clojure.gen_class@1ab2b55>
post-init.patch
3.8 KB Download
Comment 4 by cjkent, Mar 25, 2009
Great, that works perfectly. Thanks.
Comment 5 by richhickey, Apr 12, 2009
Patch applied - r1348 - thanks!
Status: Fixed
Converted from http://www.assembla.com/spaces/clojure/tickets/49
Attachments:
post-init.patch - https://www.assembla.com/spaces/clojure/documents/acQi8-w3qr3PSteJe5afGb/download/acQi8-w3qr3PSteJe5afGb
gen-class-post-init.patch - https://www.assembla.com/spaces/clojure/documents/acQlMww3qr3PSteJe5afGb/download/acQlMww3qr3PSteJe5afGb