I have this feature implemented in my 1.3.x branch in github.  I'll be
sending in the contributor agreement Monday and hopefully getting some
developer feedback thereafter.

The solution was to add a class signature when parameterized generics
are used.  Signatures are stored along with the bytecode in .class
files and used by Java's reflection capabilities, though not strictly
used by the JVM.  Parameters are specified by adding metadata
information to the :extends and :implements arguments to gen-class.

sim's use case should be solved with

(ns ExampleCollection
  (:gen-class :extends ^{:parameters [SomeItemType]}
java.util.AbstractCollect))

Note that neither the types nor constraints are checked when writing
the signature.

https://github.com/jblomo/clojure/commit/15ff4f96840788253c5af66a2265387d880bad80

Jim

On Wed, Mar 28, 2012 at 10:27 PM, Jim Blomo <jim.bl...@gmail.com> wrote:
> sim, I don't think it is possible right now.  I am not an expert, but...
>
> On Fri, Mar 2, 2012 at 5:04 AM, Daniel Solano Gomez <cloj...@sattvik.com> 
> wrote:
>> 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.
>
> This is mostly true, but for the use case needed, deriving from a
> parameterized superclass, the JVM does track the parameterized
> generic.  Class.getGenericSuperclass returns a ParameterizedType for
> Classes extending a parameterized generic.
>
> I would like this functionality as well for writing a Dropwizard
> service in Clojure.  The Dropwizard framework relies on reflecting on
> the parameter of a parent, and this doesn't seem possible in Clojure
> right now.  Writing a Java shim to do the inheritance also won't work
> with the current version of Dropwizard (though perhaps that is a
> design bug in the framework).
>
> I've taken a look at how annotations are done in generate-class, and
> would like input on the best way to add this functionality.  My rough
> plan is:
>
> - Create an implementation of ParameterizedType for Clojure
> - Add a metadata argument to the symbol passed to gen-class :extends
> or :implements
> - when that metadata is present, override getGenericSuperclass in the
> generated class to return the ParameterizedType
>
> Is this reasonable?  Are there other areas that need to expose generic
> parameters?
>
> Jim
>
> http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getGenericSuperclass()
> https://github.com/codahale/dropwizard/blob/master/dropwizard-core/src/main/java/com/yammer/dropwizard/AbstractService.java#L75

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

Reply via email to