I don’t have a ton of experience with gen-class, but I think you need to 
tell it to expose the superclass methods you want to call using 
:exposes-methods, as described 
in 
http://stackoverflow.com/questions/9060127/how-to-invoke-superclass-method-in-a-clojure-gen-class-method

In case it is of any use, here is an example of where I successfully 
subclassed a Java class from an external library and called some superclass 
methods: 
https://github.com/brunchboy/afterglow-max/blob/master/src/afterglow/max/Var.clj

On Wednesday, December 23, 2015 at 3:23:41 AM UTC-6, Kurt Sys wrote:
>
> When using gen-class and arity-overloaded methods of a superclass seems 
> not very obvious, or I am missing something...
>
> There's a (java) superclass 'some.Superclass' (which is from a library, so 
> I can't change this one):
>
> public abstract class Superclass {
>    public void method() {
>    }
>
>    public void method(Object something) {
>       this.method();
>       // other logic
>    }
> }
>
>
> I want to extend that base (abstract) class in clojure, using gen-class 
> (since the class needs to accessible as a normal Java class). So the first 
> thing I did was:
>
> (ns my.namespace
>   (:gen-class
>    :name "my.namespace.ArityTest"
>    :extends some.Superclass
>    :prefix "some-")
>  )
>
> (defn some-method
>   [this]
>   (println "1-arity"))
>
> However, this doesn't work: 'method' is arity-overloaded, when calling 
> new ArityTest().method(new Object())
>
> I get a ArityException, wrong number of arguments (2). I suppose this is 
> because I override 'method', so I have to override all arities? I'd like to 
> have the 1-arity version to call it's superclass method, and I seem to fail 
> at that. The last attempt is this: get the method of the superclass and 
> call that method on 'this':
>
> (ns be.admb.kbf.vertx.shell.test
>     (:gen-class
>       :name "my.namespace.ArityTest"
>       :extends some.Superclass
>       :prefix "some-")
>     )
>
>
> (defn some-method
>       ([this]
>         (println "1-arity"))
>       ([this o]
>         (.invoke (-> this
>                      (.getClass)
>                      (.getSuperclass)
>                      (.getMethod "method"
>                                  (into-array Class [java.lang.Object])))
>                  this (into-array Object [o]))
>         ))
>
> This fails: it calls the overriden method, not the superclass' method... 
> (and the method keeps on calling itself).
>
> The question: how do I override only 1 method of an arity-overloaded 
> method of a superclass in Clojure (using gen-class to generate a Java 
> class)?
>

-- 
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/d/optout.

Reply via email to