In Java, varargs are actually converted to arrays at compile time. It is really just some syntactic sugar allowing you to use nicer syntax for array arguments, and you can pass the arguments as an array, or as a comma delimited sequence of arguments.
On Fri, Jun 17, 2011 at 10:57 AM, Gregg Reynolds <d...@mobileink.com> wrote: > On Thu, Jun 16, 2011 at 6:12 PM, Stuart Halloway > <stuart.hallo...@gmail.com> wrote: > > > > Hi Gregg, > > It appears that LocalServiceTestHelper's constructor takes an array > of LocalServiceTestConfig. Try > > (def bar (LocalServiceTestHelper. (into-array LocalServiceTestConfig > [foo]))) > > Stu > > Hi Stu, > > Would you be the Stuart Halloway whose "Programming Clojure" book I > bought last week? Nice work! > Using into-array indeed solved the problem - I even found it in the > book, p. 85. But if you're taking notes for the second edition this > might be a good item for a "Java Interop Gotchas" list. The method > definition looks like this: > > public LocalServiceTestHelper(LocalServiceTestConfig... configs) > > I.e. it uses the varargs op ... instead of []. The sample code uses: > > ... = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); > > i.e. it passes a single object, not an array. The clojure code > without into-array complains about bad class casting. So it looks > like there is a minor impedance mismatch between Java and Clojure when > it comes to varargs, unless I missed something. The rule seems to be: > if the Java method takes varargs, pass it an explicit array. > > Thanks > > Gregg > > -- > 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 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