When using gen-class and arity-overloaded methods of a superclass seems not
very obvious, or I am missing something :p.
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: since '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 one. 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.namexpace.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...
So well, how do I override only 1 method of an arity-overloaded method of a
superclass in Clojure?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.