Hacker News new | ask | show | jobs
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.

1 comments

I've never found it to be that awkward to extend existing classes from java. Part of the problem in clojure are there are so many different ways to do it, all with different shortcomings.

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_...

Ya. I was implementing an abstract class so gen-class was the only way.