Hi Daniel, Thanks for that but what if the type your extending is parameterised? For example using your example:
(ns ExampleCollection (:gen-class :extends java.util.AbstractCollection<SomeItemType>)) How do I do the <SomeItemType> bit? Forgive me if this is obvious my java foo is weak :) -- sim On Saturday, 3 March 2012 00:04:21 UTC+11, Daniel Solano Gómez wrote: > > On Thu Mar 1 21:53 2012, sim wrote: > > Hi all, > > > > This has me stumped and I found another message: > > > https://groups.google.com/forum/?fromgroups#!searchin/clojure/parameterised$20type/clojure/8YxzIYXH49c/xCxkMaGXBzUJ > > > > > > that says it isn't possible, but that was back in 2009, is it still not > > possible? Any work arounds apart from doing some of it in Java? > > > > I would like to be able to write some xWiki Macros in clojure, I have > some > > in java already but moving it all to clojure would be better. > > > > The java example is as follows: > > > > public class ExampleMacro extends AbstractMacro<ExampleMacroParameters> > > > > Which is from here: > > http://rendering.xwiki.org/xwiki/bin/view/Main/ExtendingMacro > > > > Any help/pointers would be greatly appreciated. > > > > -- sim > > Yes, it is possible. At the byte-code level there is (at least at > run-time) no difference between a generic and a non-generic class. All > methods take/return the generic type just use Object. > > For example, take the following implementation of AbstractCollection<E>: > > --- begin ExampleCollection.clj --- > > (ns ExampleCollection > (:gen-class :extends java.util.AbstractCollection)) > > (def some-numbers [2 3 5 7 11 13]) > > (defn -size [_] (count some-numbers)) > > (defn -iterator [_] (.iterator some-numbers)) > > > --- end ExampleCollection.clj --- > > You can use it as in the following: > > --- begin Example.java --- > import java.util.Collection; > > public class Example { > public static void main(String[] args) { > Collection<Long> foo = new ExampleCollection(); > for (Long bar : foo) { > System.out.println(bar); > } > } > } > --- end Example.java --- > > The Java file will compile and run, though it will complain about doing > an unsafe conversion. This means that if the type that occurs at > runtime is wrong, you'll get a ClassCastException. > > In any case, you can also use proxies to accomplish the same task if you > don't want to gen-class. > > I hope this helps. > > Sincerely, > > Daniel > > -- 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