tags:

views:

103

answers:

2

I'm calling the twitter4j library using Clojure like so:

(def twitter (. (TwitterFactory.) getInstance))

This works fine when I call it as a script. But when I use gen-class, I get:

java.lang.IllegalArgumentException: Can't call public method of non-public class: public java.lang.Object twitter4j.TwitterFactoryBase.getInstance()

Is there a workaround for this?

A: 

I have no experience with it myself, but Meikel Brandmeyer did a nice writeup on gen-class once, maybe that will help you:

http://kotka.de/blog/2010/02/gen-class_how_it_works_and_how_to_use_it.html

Michael Kohl
A: 

Try:

(def twitter (.getInstance (new TwitterFactory)))
lazy1
That makes no difference whatsoever. Why would it?
sramsay
I don't know what's the cause for the difference (being a clojure newbie). However it works for me :)
lazy1
Wait. Really? I thought the difference was just syntactic sugar (I actually prefer your way -- it seems "lispier" to me).
sramsay
@sramsay - you're correct, there is no difference. In fact, you can see how the `Foo.` macro gets expanded to `new Foo` by entering `(macroexpand '(Foo.))` in your REPL. You can also expand `(.bar baz)` in the same way to `(. baz bar)`
rcampbell