|
|
|
|
|
by rickmode
5489 days ago
|
|
Using Java classes and interfaces from Clojure is straightforward. Instantiating objects is easy. Implementing Java interfaces is easy. Both are fluid and feel idiomatic. On the other hand, extending an existing Java class is quite awkward, requiring the use of gen-class, and does not (IMHO) feel idiomatic. I found the gen-class facility poorly documented. It also has a potentially small performance penalty due to an extra dereference (though in my testing I could not measure a meaningful difference between a gen-class object and a native Java implementation). So Clojure is nice for using Java stuff from Clojure, however it becomes awkward for using Clojure stuff from Java. |
|
For simple adding of a protocol to a class you can always just use (extend-class)
Proxies are simple and work well in other cases.
the gen-class documentation is a bit confusing, it helped me to look @ some examples. I used a different site that I can't find now, but this one seems helpful.
http://kotka.de/blog/2010/02/gen-class_how_it_works_and_how_...