Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle specific case Java variable length arguments in Clojure?
    primarykey
    data
    text
    <p>I'm trying to port some Java code to Clojure and I ran into a situation that I can't solve.</p> <p>Normally when you want call a Java constructor or method with a variable length argument you do something like this</p> <pre><code>(Fields. (into-array Comparable ["predict", "other"])) </code></pre> <p>However I found a special example where this doesn't work:</p> <pre><code>(Fields. (into-array Comparable ["predict", Double])) </code></pre> <p>Although this seems possible in Java (see below), the code above gives the following error:</p> <pre><code>IllegalArgumentException array element type mismatch java.lang.reflect.Array.set (Array.java:-2) </code></pre> <p>I tried a couple of variations, but nothing seems to work. The Java code I try to port (and the specific line that gives trouble) is here <a href="https://github.com/Cascading/pattern/blob/wip-1.0/pattern-examples/src/main/java/cascading/pattern/Main.java#L76" rel="nofollow">https://github.com/Cascading/pattern/blob/wip-1.0/pattern-examples/src/main/java/cascading/pattern/Main.java#L76</a></p> <pre><code>new Fields( "predict", Double.class ) </code></pre> <p>(The constructor signature for Fields is Fields(Comparable... fields) <a href="http://docs.cascading.org/cascading/2.1/javadoc/cascading/tuple/Fields.html#Fields(java.lang.Comparable...)" rel="nofollow">http://docs.cascading.org/cascading/2.1/javadoc/cascading/tuple/Fields.html#Fields(java.lang.Comparable...)</a></p> <p>I tried the following examples in the Clojure repl:</p> <pre><code>(into-array Comparable [(type Double)]) (into-array Comparable [Double/TYPE]) (into-array Comparable [Double]) =&gt; IllegalArgumentException array element type mismatch java.lang.reflect.Array.set (Array.java:-2) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload