On May 28, 2009, at 5:23 PM, tsuraan wrote:

I have a java class whose constructor expects (among other things) a
BlockingQueue<Long>.  It's easy to create a BlockingQueue in clojure
(obviously), but I can't figure out the syntax to specialize it to the
Long type.  Is this possible, or does it even make sense?  I seem to
recall that generics are just hints for the java compiler and not
actually enforced by the runtime, which would imply that clojure has
no need to support them.  Is that the case?

I think your conclusion is correct.

Here's an example with java.lang.Class and clojure.contrib.repl-utils/ show:

The Java 1.5 docs for Class.asSubClass show that it takes a generic as an argument and returns a generic:

        <U> Class<? extends U> asSubclass(Class<U> clazz)
Casts this Class object to represent a subclass of the class represented by the specified class object.

        http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html

Compare that with the reflection info shown by clojure.contrib.repl- utils/show:

        user=> (show Class)
        ===  public final java.lang.Class  ===
        [ 0] static forName : Class (String)
        [ 1] static forName : Class (String,boolean,ClassLoader)
        [ 2] asSubclass : Class (Class)
        [...]
        nil
        user=> (show Class 2)
#<Method public java.lang.Class java.lang.Class.asSubclass(java.lang.Class)>

This shows that the entry point is at some level "really" expecting a Class and returning a Class.

I've done this in practice in a different context and it worked fine.

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to