The vararg at the end of the method is just syntactic sugar for an array, so the "add" method actually takes 4 args, the last being a Resource array. The java compiler just replaces "missing" varargs with an empty array.
My guess is that the reflection mechanisms in the compiler just look at type/arity. The Method object has a isVarArg() boolean, so that could be used to allow omitting varargs altogether. That would need to be an enhancement to the clojure compiler, so I opened a ticket: https://www.assembla.com/spaces/clojure/tickets/440-java-method-calls-cannot-omit-varargs On Sep 27, 1:16 pm, JonathanBelolo <[email protected]> wrote: > While toying with the Sesame2.3 library, I've come across the > following behavior for the first time. > > This is taken from the api doc for > org.openrdf.repository.base.RepositoryConnectionBase: > > add(Resource subject, URI predicate, Value object, Resource... > contexts) > Adds a statement with the specified subject, predicate and > object to this repository, optionally to one or more named contexts. > > But apparently, Clojure seems to think the optional args are > mandatory... > > (.add con alice RDF/TYPE person) > > No matching method found: add for class > org.openrdf.repository.sail.SailRepositoryConnection > [Thrown class java.lang.IllegalArgumentException] > > So I run > > (grep #".add" (.getMethods (.getClass con))) > > #<Method public void > org.openrdf.repository.base.RepositoryConnectionBase.add(org.openrdf.model. > Resource,org.openrdf.model.URI,org.openrdf.model.Value,org.openrdf.model.Re > source[]) > throws org.openrdf.repository.RepositoryException>) > > Finally the following works... > > (.add con alice RDF/TYPE person (make-array Resource 1)) > nil > > Is this behavior normal? Are optional args mandatory when called with > interop? > > Thanks for your help :) > > Jonathan -- 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
