<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged java-interop</title>
<link>https://ask.clojure.org/index.php/tag/java-interop</link>
<description></description>
<item>
<title>Reflection warning when long hint on an argument</title>
<link>https://ask.clojure.org/index.php/15067/reflection-warning-when-long-hint-on-an-argument</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I noticed some reflection warning that goes away when &lt;em&gt;removing&lt;/em&gt; a hint from fn arguments. I would like to understand the reason for this.&lt;/p&gt;
&lt;p&gt;Example, loading this code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(set! *warn-on-reflection* true)

(defn duration-of-seconds
  (^java.time.Duration [^long seconds]
   (java.time.Duration/ofSeconds seconds)))

(defn sleep
  [seconds]
  (Thread/sleep (duration-of-seconds seconds)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Raises a reflection warning:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;call to static method sleep on java.lang.Thread can't be resolved (argument types: java.lang.Object).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, just removing the &lt;code&gt;^long&lt;/code&gt; hint from the &lt;code&gt;duration-of-seconds&lt;/code&gt; fn argument, makes the reflection warning go away.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15067/reflection-warning-when-long-hint-on-an-argument</guid>
<pubDate>Fri, 01 May 2026 19:49:31 +0000</pubDate>
</item>
<item>
<title>Why does a qualified instance method call fails at compile time with NullPointerException if missing target</title>
<link>https://ask.clojure.org/index.php/14596/qualified-instance-compile-nullpointerexception-missing</link>
<description>&lt;p&gt;Has anyone else noticed a lot of Syntax error (NullPointerException) when using the new Class/.instanceMethod syntax? Specifically whenever I forget the first argument like &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(fn [] (String/.length))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;gets&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#error{:cause &quot;Cannot invoke \&quot;clojure.lang.Compiler$Expr.emit(clojure.lang.Compiler$C, clojure.lang.Compiler$ObjExpr, clojure.asm.commons.GeneratorAdapter)\&quot; because \&quot;this.target\&quot; is null&quot;,
       :via [{:type clojure.lang.Compiler$CompilerException,
              :message &quot;Syntax error compiling fn* at (/private/var/folders/cr/wpw7hgnx0jj9m33g28rtbpzc0000gn/T/form-init4871175438924650637.clj:1:1).&quot;,
              :data #:clojure.error{:phase :compile-syntax-check,
                                    :line 1,
                                    :column 1,
                                    :source &quot;/private/var/folders/cr/wpw7hgnx0jj9m33g28rtbpzc0000gn/T/form-init4871175438924650637.clj&quot;,
                                    :symbol fn*},
              :at [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7677]}
             {:type java.lang.NullPointerException,
              :message &quot;Cannot invoke \&quot;clojure.lang.Compiler$Expr.emit(clojure.lang.Compiler$C, clojure.lang.Compiler$ObjExpr, clojure.asm.commons.GeneratorAdapter)\&quot; because \&quot;this.target\&quot; is null&quot;,
              :at [clojure.lang.Compiler$InstanceMethodExpr emit &quot;Compiler.java&quot; 2060]}],
       :trace [[clojure.lang.Compiler$InstanceMethodExpr emit &quot;Compiler.java&quot; 2060]
               [clojure.lang.Compiler$BodyExpr emit &quot;Compiler.java&quot; 6723]
               [clojure.lang.Compiler$FnMethod doEmit &quot;Compiler.java&quot; 6243]
               [clojure.lang.Compiler$FnMethod emit &quot;Compiler.java&quot; 6045]
               [clojure.lang.Compiler$FnExpr emitMethods &quot;Compiler.java&quot; 4500]
               [clojure.lang.Compiler$ObjExpr compile &quot;Compiler.java&quot; 5136]
               [clojure.lang.Compiler$FnExpr parse &quot;Compiler.java&quot; 4662]
               [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7667]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7360]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7316]
               [clojure.lang.Compiler$BodyExpr$Parser parse &quot;Compiler.java&quot; 6683]
               [clojure.lang.Compiler$FnMethod parse &quot;Compiler.java&quot; 6022]
               [clojure.lang.Compiler$FnExpr parse &quot;Compiler.java&quot; 4585]
               [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7667]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7360]
               [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7736]
               [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7694]
               [clojure.core$eval invokeStatic &quot;core.clj&quot; 3232]
               [clojure.core$eval invoke &quot;core.clj&quot; 3228]
               [nrepl.middleware.interruptible_eval$evaluate$fn__966$fn__967 invoke &quot;interruptible_eval.clj&quot; 87]
               [clojure.lang.AFn applyToHelper &quot;AFn.java&quot; 152]
               [clojure.lang.AFn applyTo &quot;AFn.java&quot; 144]
               [clojure.core$apply invokeStatic &quot;core.clj&quot; 667]
               [clojure.core$with_bindings_STAR_ invokeStatic &quot;core.clj&quot; 1990]
               [clojure.core$with_bindings_STAR_ doInvoke &quot;core.clj&quot; 1990]
               [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 428]
               [nrepl.middleware.interruptible_eval$evaluate$fn__966 invoke &quot;interruptible_eval.clj&quot; 87]
               [clojure.main$repl$read_eval_print__9248$fn__9251 invoke &quot;main.clj&quot; 437]
               [clojure.main$repl$read_eval_print__9248 invoke &quot;main.clj&quot; 437]
               [clojure.main$repl$fn__9257 invoke &quot;main.clj&quot; 459]
               [clojure.main$repl invokeStatic &quot;main.clj&quot; 459]
               [clojure.main$repl doInvoke &quot;main.clj&quot; 368]
               [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 1526]
               [nrepl.middleware.interruptible_eval$evaluate invokeStatic &quot;interruptible_eval.clj&quot; 84]
               [nrepl.middleware.interruptible_eval$evaluate invoke &quot;interruptible_eval.clj&quot; 56]
               [nrepl.middleware.interruptible_eval$interruptible_eval$fn__997$fn__1001
                invoke
                &quot;interruptible_eval.clj&quot;
                152]
               [clojure.lang.AFn run &quot;AFn.java&quot; 22]
               [nrepl.middleware.session$session_exec$main_loop__1065$fn__1069 invoke &quot;session.clj&quot; 202]
               [nrepl.middleware.session$session_exec$main_loop__1065 invoke &quot;session.clj&quot; 201]
               [clojure.lang.AFn run &quot;AFn.java&quot; 22]
               [java.lang.Thread run &quot;Thread.java&quot; 1447]]}
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14596/qualified-instance-compile-nullpointerexception-missing</guid>
<pubDate>Mon, 30 Jun 2025 13:33:36 +0000</pubDate>
</item>
<item>
<title>Idiomatic way to use java.util.Optional</title>
<link>https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional</link>
<description>&lt;p&gt;Is there an easy way to work with &lt;code&gt;java.utils.Optional&lt;/code&gt; values in Clojure? I'm currently using 1.12 so I can say things like &lt;code&gt;(Optional/.orElse foo nil)&lt;/code&gt; to convert the optional value to a &quot;normal&quot; value (X or nil), but that and other Optional methods are still sources of tension or boilerplate compared idiomatic Clojure constructs (&lt;code&gt;some-&amp;gt;&lt;/code&gt; for example).&lt;/p&gt;
&lt;p&gt;If such a way doesn't currently exist, can it be considered for addition to Clojure? Maybe opening up &lt;code&gt;deref&lt;/code&gt; to work on Optionals as well.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional</guid>
<pubDate>Mon, 07 Apr 2025 14:16:59 +0000</pubDate>
</item>
<item>
<title>core.async go block error with clojure 1.12 method values</title>
<link>https://ask.clojure.org/index.php/14425/core-async-go-block-error-with-clojure-1-12-method-values</link>
<description>&lt;p&gt;I haven't seen this reported. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(Long/.toString 123) ;;works
(a/&amp;lt;!! (a/thread (Long/.toString 123))) ;;works
(a/go (Long/.toString 123)) ;;error
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;Note: The following stack trace applies to the reader or compiler, your code was not executed.

CompilerException Syntax error macroexpanding a/go at (1:1). {:clojure.error/phase :macro-syntax-check, :clojure.error/line 1, :clojure.error/column 1, :clojure.error/source &quot;NO_SOURCE_PATH&quot;, :clojure.error/symbol a/go}
ExceptionInfo No matching method: .toString for class: class java.lang.Long and arity: 1 {:method .toString, :class java.lang.Long, :argc 1, :file &quot;NO_SOURCE_PATH&quot;, :column 7, :line 1}
	clojure.tools.analyzer.passes.jvm.validate/validate-call (validate.clj:127)
	clojure.tools.analyzer.passes.jvm.validate/validate-call (validate.clj:87)
	clojure.tools.analyzer.passes.jvm.validate/eval4802/fn--4803 (validate.clj:137)
	clojure.lang.MultiFn.invoke (MultiFn.java:229)
	clojure.tools.analyzer.passes.jvm.validate/validate (validate.clj:265)
	clojure.tools.analyzer.passes.jvm.validate/validate (validate.clj:240)
	clojure.lang.Var.invoke (Var.java:386)
	clojure.tools.analyzer.passes/compile-passes/fn--3424/fn--3429 (passes.clj:167)
	clojure.tools.analyzer.passes/compile-passes/fn--3424/fn--3431 (passes.clj:169)
	clojure.tools.analyzer.passes/compile-passes/fn--3424/fn--3431 (passes.clj:169)
	clojure.tools.analyzer.passes/compile-passes/fn--3424/fn--3431 (passes.clj:169)
	clojure.core/partial/fn--5929 (core.clj:2648)
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>core.async</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14425/core-async-go-block-error-with-clojure-1-12-method-values</guid>
<pubDate>Tue, 25 Feb 2025 19:17:23 +0000</pubDate>
</item>
<item>
<title>Do stream interop functions close the stream?</title>
<link>https://ask.clojure.org/index.php/14376/do-stream-interop-functions-close-the-stream</link>
<description>&lt;p&gt;Docs for the handy new stream interop functions (&lt;code&gt;stream-seq!&lt;/code&gt;, &lt;code&gt;stream-into!&lt;/code&gt; etc) say they &quot;are terminal stream operations (they consume the stream).&quot;&lt;/p&gt;
&lt;p&gt;Just to be totally clear, does this mean they close (&lt;code&gt;.close&lt;/code&gt;) the streams?&lt;/p&gt;
&lt;p&gt;I ask because I use these functions with the stream returned from &lt;code&gt;java.nio.file.Files/list&lt;/code&gt; and when I'm benchmarking the app I sometimes get &quot;too many open files&quot; Java errors. I can't think where else I might conceivably be leaving a file handle open, beyond that I'm almost entirely just using &lt;code&gt;slurp&lt;/code&gt; (for now at least).&lt;/p&gt;
&lt;p&gt;(Naively, I would expect everything except &lt;code&gt;stream-seq!&lt;/code&gt; to close out the stream by the time it returns, and &lt;code&gt;stream-seq!&lt;/code&gt; I would expect to close once the seq is consumed and/or garbage collected)&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14376/do-stream-interop-functions-close-the-stream</guid>
<pubDate>Sat, 08 Feb 2025 16:23:45 +0000</pubDate>
</item>
<item>
<title>Using integer parameters in deftype annotations</title>
<link>https://ask.clojure.org/index.php/13998/using-integer-parameters-in-deftype-annotations</link>
<description>&lt;p&gt;I am trying to use a Java library that uses annotations on Java classes and methods, so I pass to it deftypes with annotated methods. Some of the annotations require using integer parameters and it seems there is no  convenient way to do this in Clojure. The code I am trying is something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(deftype SomeType []
  (^{Retention RetentionPolicy/RUNTIME
     SomeAnnotationClass {:order 1} }
   someMethod [_]...)) 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;:order 1&lt;/code&gt; part causes an exception:&lt;/p&gt;
&lt;p&gt; &lt;code&gt;Incorrectly typed data found for annotation element ... (Found data of type java.lang.Long[1])&lt;/code&gt; &lt;/p&gt;
&lt;p&gt;This happens because the java library expects that &lt;code&gt;:order&lt;/code&gt; would have a java.lang.Integer value, but Clojure creates a java.lang.Long. If I try (int 1)  instead of 1, I get another exception.&lt;/p&gt;
&lt;p&gt;I asked for help on clojurians Slack, and it was suggested that I use &lt;code&gt;#java.lang.Integer[1]&lt;/code&gt; instead of simply 1. This works, but it would be nice to have a more intuitive way to do this.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13998/using-integer-parameters-in-deftype-annotations</guid>
<pubDate>Sun, 30 Jun 2024 18:44:17 +0000</pubDate>
</item>
<item>
<title>Why does compilation of fn fail when referencing a class with a failing static field initializer?</title>
<link>https://ask.clojure.org/index.php/13810/compilation-referencing-class-failing-static-initializer</link>
<description>&lt;p&gt;Given a Clojure function which references a class, if that class has a static field with an initializer which fails when run, the function will fail to compile because the compiler (needlessly) runs the initializer even if the respective field is not accessed. Notably, this does &lt;em&gt;not&lt;/em&gt; happen when storing the class in a var and then referencing it through that instead (see workaround below). Could the compiler support the direct reference here?&lt;/p&gt;
&lt;h2&gt;Reproducer&lt;/h2&gt;
&lt;p&gt;(The following code is also available at &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/bevuta/clojure-fn-compilation-issue-repro&quot;&gt;https://github.com/bevuta/clojure-fn-compilation-issue-repro&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;deps.edn&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:deps {io.netty/netty-codec {:mvn/version &quot;4.1.108.Final&quot;}}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;src/repro/fail.clj&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro.fail
  (:import io.netty.handler.codec.compression.BrotliOptions))

(defn bar []
  BrotliOptions)

(defn -main [&amp;amp; args]
  (prn (bar)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, the &lt;code&gt;bar&lt;/code&gt; function references the &lt;code&gt;io.netty.handler.codec.compression.BrotliOptions&lt;/code&gt; class. That class has &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/netty/netty/blob/c1d0fd2dbf7907a99ab702795e35d9de8068c1cb/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java#L32-L34&quot;&gt;a package-private static field named &lt;code&gt;DEFAULT&lt;/code&gt;&lt;/a&gt; with an initializer. That initializer depends on a class which is provided by an optional third-party library. However, even though &lt;code&gt;bar&lt;/code&gt; never references that field, the initializer gets run and fails because that library is not present.&lt;/p&gt;
&lt;p&gt;Run it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ clojure -M -m repro.fail
Execution error (ClassNotFoundException) at jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).
com.aayushatharva.brotli4j.encoder.Encoder$Parameters
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Workaround&lt;/h2&gt;
&lt;p&gt;The issue can be worked around by putting the class value into a separate &lt;code&gt;def&lt;/code&gt; and using that in the function instead:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;src/repro/ok.clj&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro.ok
  (:import io.netty.handler.codec.compression.BrotliOptions))

(def foo BrotliOptions)

(defn bar []
  foo)

(defn -main [&amp;amp; args]
  (prn (bar)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ clojure -M -m repro.ok
io.netty.handler.codec.compression.BrotliOptions
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Relevance&lt;/h2&gt;
&lt;p&gt;The issue was encountered in the context of &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clj-commons/aleph/issues/703&quot;&gt;https://github.com/clj-commons/aleph/issues/703&lt;/a&gt;&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13810/compilation-referencing-class-failing-static-initializer</guid>
<pubDate>Mon, 08 Apr 2024 15:01:01 +0000</pubDate>
</item>
<item>
<title>How to use the AWS S3 Java API v2 `S3Configuration`?</title>
<link>https://ask.clojure.org/index.php/13794/how-to-use-the-aws-s3-java-api-v2-s3configuration</link>
<description>&lt;p&gt;I want to turn this Java code into Clojure&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;S3Client.builder()
      .serviceConfiguration(S3Configuration.builder()
            .pathStyleAccessEnabled(true)
            .build())
      .build();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Problem: &lt;code&gt;.seviceConfiguration&lt;/code&gt; takes a &lt;code&gt;java.util.function.Conumser&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;default B serviceConfiguration(Consumer&amp;lt;S3Configuration.Builder&amp;gt; serviceConfiguration)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;.servcieConfiguration method&lt;/code&gt; is defined here &lt;a rel=&quot;nofollow&quot; href=&quot;https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3BaseClientBuilder.html#serviceConfiguration(java.util.function.Consumer)&quot;&gt;AWS SDK serviceConfiguration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I tried to use &lt;code&gt;reify&lt;/code&gt; without much luck.&lt;/p&gt;
&lt;p&gt;Maybe someone can point me into the right direction, or has already used this specific part of the API.&lt;/p&gt;
&lt;p&gt;And can someone tell me why, is an API design like this advantageous for Java Developers, what is the point of this Construct?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13794/how-to-use-the-aws-s3-java-api-v2-s3configuration</guid>
<pubDate>Tue, 26 Mar 2024 08:44:25 +0000</pubDate>
</item>
<item>
<title>Why can't I type hint these floats?</title>
<link>https://ask.clojure.org/index.php/13743/why-cant-i-type-hint-these-floats</link>
<description>&lt;p&gt;I want to ensure I'm using unboxed and unreflected arithmetic on arrays of floats, but I can't get it to compile.&lt;/p&gt;
&lt;p&gt;How can I type hint a float in a function like this?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;&lt;br&gt;
(defn ff2a&lt;/p&gt;
&lt;p&gt;  ^&quot;[F&quot; ; Return type hint for a float array&lt;/p&gt;
&lt;p&gt;  [^float f1 ^float f2] ; Argument type hints&lt;/p&gt;
&lt;p&gt;  (float-array [f1 f2]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I get this error when I try to load it into the REPL:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Syntax error (IllegalArgumentException) compiling fn* [...] Only long and double primitives are supported&lt;/code&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13743/why-cant-i-type-hint-these-floats</guid>
<pubDate>Thu, 15 Feb 2024 18:48:26 +0000</pubDate>
</item>
<item>
<title>Do primitive type hints in fn arguments turns the return value as an Object?</title>
<link>https://ask.clojure.org/index.php/13501/primitive-type-hints-arguments-turns-the-return-value-object</link>
<description>&lt;p&gt;Hi everyone,&lt;br&gt;
I was playing around with java-interop and found this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(set! *warn-on-reflection* true)

(import [java.util.concurrent ScheduledExecutorService Executors ScheduledFuture TimeUnit])

(defonce ^:private ^ScheduledExecutorService executor (Executors/newScheduledThreadPool 1))

(defn set-timeout-primitive ^ScheduledFuture [^long ms ^Callable f]
  (.schedule executor f ms TimeUnit/MILLISECONDS))

(defn set-timeout-object ^ScheduledFuture [^Long ms ^Callable f]
  (.schedule executor f ms TimeUnit/MILLISECONDS))

(.get (set-timeout-primitive 2000 (fn [] (println :done) :done))) ; Reflection warning, ... - reference to field get on java.lang.Object can't be resolved.
(.get (set-timeout-object 2000 (fn [] (println :done) :done))) ; No warnings
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The reason for this reflection warning (thanks for &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians.slack.com/archives/C03S1KBA2/p1701334231189649&quot;&gt;explaining&lt;/a&gt;) seems to be that when the compiler looks for the matching interface it finds this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static public interface OLOO{Object invokePrim(Object arg0, long arg1, Object arg2);}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the return value becomes an &lt;code&gt;Object&lt;/code&gt; and not a &lt;code&gt;ScheduledFuture&lt;/code&gt;. But this doesn't happen when using a &lt;code&gt;^Long&lt;/code&gt; type hint instead of a &lt;code&gt;^long&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Could this be improved? Thank you!&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13501/primitive-type-hints-arguments-turns-the-return-value-object</guid>
<pubDate>Fri, 01 Dec 2023 18:42:52 +0000</pubDate>
</item>
<item>
<title>Built-in function for Thread/sleep to avoid type hints</title>
<link>https://ask.clojure.org/index.php/12853/built-in-function-for-thread-sleep-to-avoid-type-hints</link>
<description>&lt;p&gt;From JDK19+ onwards, the following becomes reflective without adding a type hint:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def x 10)
(Thread/sleep x)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The tricky bit is that in earlier JDKs the above did not reflect, but when you upgrade your JDK, the reflection starts.&lt;/p&gt;
&lt;p&gt;If using native-image, your program may start to fail due to missing reflection configuration.&lt;/p&gt;
&lt;p&gt;It would be nice to have a built-in sleep function that accepted a number so we don't forget to add type hints and it would work consistently across JDKs.&lt;/p&gt;
&lt;p&gt;E.g.:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns clojure.java.misc)
(defn sleep [x]
  (if (number? x)
    (Thread/sleep (long x))
    ....)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A better name for &lt;code&gt;clojure.java.misc&lt;/code&gt; is welcome. Maybe just &lt;code&gt;clojure.java&lt;/code&gt; or put this function into &lt;code&gt;clojure.core&lt;/code&gt;?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12853/built-in-function-for-thread-sleep-to-avoid-type-hints</guid>
<pubDate>Fri, 14 Apr 2023 17:52:34 +0000</pubDate>
</item>
<item>
<title>java interop isn't working for me</title>
<link>https://ask.clojure.org/index.php/12494/java-interop-isnt-working-for-me</link>
<description>&lt;p&gt;Just when I think i'm getting the hang of clojure/java interop, i get&lt;br&gt;
stumped!&lt;/p&gt;
&lt;p&gt;I want to make use of some &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/crillab/jkahypar&quot;&gt;java code,jkahypar&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;It is nicely registered in Maven, and I have a slug in my projects.clj:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[fr.cril/jkahypar &quot;0.2.0&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can import the particular tool I am starting with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(import fr.univartois.cril.jkahypar.tools.HypergraphParser)
=&amp;gt; fr.univartois.cril.jkahypar.tools.HypergraphParser

(type HypergraphParser)
=&amp;gt; java.lang.Class
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;what i can NOT do is call either of the class's constructor methods,&lt;br&gt;
using either a &lt;code&gt;String&lt;/code&gt; or &lt;code&gt;InputStream&lt;/code&gt; for the data file path:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def tf &quot;.../graphs/add20.metis&quot;)

(def fs (clojure.java.io/input-stream tf))
(type fs)
=&amp;gt; java.io.BufferedInputStream
	
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(def hgp (HypergraphParser/HypergraphParser tf))&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Syntax error (IllegalArgumentException) compiling . at (/private/var/folders/dz/8plg36qs1r50kjb6wvn4dwh00000gn/T/form-init7854241673144140259.clj:1:10).
No matching method HypergraphParser found taking 1 args for class fr.univartois.cril.jkahypar.tools.HypergraphParser
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(def hgp (HypergraphParser/HypergraphParser fs))&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Syntax error (IllegalArgumentException) compiling . at (/private/var/folders/dz/8plg36qs1r50kjb6wvn4dwh00000gn/T/form-init7854241673144140259.clj:1:10).
No matching method HypergraphParser found taking 1 args for class fr.univartois.cril.jkahypar.tools.HypergraphParser
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;i've tried a bunch of other variants on this, but nothing seems to&lt;br&gt;
work.  &lt;/p&gt;
&lt;p&gt;is there a way to get (&quot;reflect&quot;?) the methods available on this class that might let me know what is amiss?  i'm used to having my Cursive IDE pop up prompts (eg, telling me it knew of &lt;code&gt;HypergraphParser&lt;/code&gt;), but i don't get any when I type the slash &lt;code&gt;/&lt;/code&gt; after this class?&lt;/p&gt;
&lt;p&gt;any ideas what am i doing wrong, please?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12494/java-interop-isnt-working-for-me</guid>
<pubDate>Thu, 22 Dec 2022 00:49:35 +0000</pubDate>
</item>
<item>
<title>How to set environment variables to an interactive process spawned by ProcessBuilder?</title>
<link>https://ask.clojure.org/index.php/12362/environment-variables-interactive-process-processbuilder</link>
<description>&lt;p&gt;I managed to get an interactive CLI working from: &lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/questions/56541688/how-to-run-an-interactive-cli-program-from-within-clojure&quot;&gt;https://stackoverflow.com/questions/56541688/how-to-run-an-interactive-cli-program-from-within-clojure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;but I also need to set the environment varibles, &lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/questions/30574972/java-processbuilder-and-using-environment-variables&quot;&gt;https://stackoverflow.com/questions/30574972/java-processbuilder-and-using-environment-variables&lt;/a&gt; suggests &lt;code&gt;pb.environment().put(&quot;ENV&quot;, &quot;val&quot;)&lt;/code&gt; so I think it should be &lt;code&gt;(-&amp;gt; pb .environment (put. env val))&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn process-interactive-cli
  [args &amp;amp; [working-directory envs]]
  (let [process-builder (java.lang.ProcessBuilder. args)
        inherit (java.lang.ProcessBuilder$Redirect/INHERIT)
        environment (.environment process-builder)]
    ;; change CWD
    (when working-directory
      (.directory process-builder (io/file working-directory)))
    ;; set environment variables
    (for [[env val] envs]
      (.put environment env val))
    (.redirectOutput process-builder inherit)
    (.redirectError process-builder inherit)
    (.redirectInput process-builder inherit)
    ;; print the executing command (~ set -x)
    (apply println &quot;&amp;gt;&quot; args)
    (.waitFor (.start process-builder))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But debugging this gives me:&lt;br&gt;
&lt;code&gt;1. Unhandled java.lang.IllegalArgumentException
   No matching method put found taking 2 args for class
   java.lang.ProcessEnvironment$StringEnvironment&lt;/code&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12362/environment-variables-interactive-process-processbuilder</guid>
<pubDate>Sun, 06 Nov 2022 14:15:47 +0000</pubDate>
</item>
<item>
<title>Could deftype allow for overriding methods?</title>
<link>https://ask.clojure.org/index.php/12113/could-deftype-allow-for-overriding-methods</link>
<description>&lt;p&gt;Currently implementing a custom &lt;code&gt;java.util.Iterator&lt;/code&gt; with the usual deftype form like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(deftype MyIterator []
  Iterator
  (hasNext [this]
    (my-custom-code))
  (next [this]
    (my-custom-code))
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But I'd like to override the &lt;code&gt;forEachRemaining&lt;/code&gt; default method on &lt;code&gt;Iterator&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;default void forEachRemaining(Consumer&amp;lt;? super E&amp;gt; action) {
    Objects.requireNonNull(action);
    while (hasNext())
        action.accept(next());
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;... with a more performant/specialized implementation. Perhaps I would even want to implement the by-default unimplemented &lt;code&gt;remove&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;default void remove() {
    throw new UnsupportedOperationException(&quot;remove&quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But deftype does not allow for overriding methods. Is this a fundamental limitation or just something that hasn't been done (probably because Clojure predates default methods in java 8)? Anyways as a language whose philosophy is to embrace the the host, this would come in highly useful for using/integrating with java interfaces.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12113/could-deftype-allow-for-overriding-methods</guid>
<pubDate>Sat, 13 Aug 2022 16:52:31 +0000</pubDate>
</item>
<item>
<title>Runtime.Version nested class (JDK 9+)  is not automatically imported?</title>
<link>https://ask.clojure.org/index.php/12060/runtime-version-nested-class-jdk-not-automatically-imported</link>
<description>&lt;p&gt;In JDK 9 a new nested class Runtime.Version has been introduced.&lt;br&gt;
However, I cannot use it without using the fully qualified name: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(Runtime$Version/parse (System/getProperty &quot;java.version&quot;))
Syntax error compiling at ...
No such namespace: Runtime$Version

;; fully qualified name works
(java.lang.Runtime$Version/parse (System/getProperty &quot;java.version&quot;))
#object[java.lang.Runtime$Version 0x39a4ea03 &quot;11.0.2&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is this intended?&lt;br&gt;
I quickly tried this with another (private) nested class and it's the same behavior: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;String$CaseInsensitiveComparator
Syntax error compiling ...
Unable to resolve symbol: String$CaseInsensitiveComparator in this context
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/java_interop&quot;&gt;Java Interop reference&lt;/a&gt; says that nested classes can be accessed as &lt;code&gt;Classname$NestedClassName&lt;/code&gt; and doesn't mention this issue specifically.&lt;br&gt;
It does look a bit inconsistent to me.&lt;/p&gt;
&lt;p&gt;To be fair, I can still import the nested class and use it - but this is something I didn't expect I had to do: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(import 'java.lang.Runtime$Version)
(Runtime$Version/parse (System/getProperty &quot;java.version&quot;))
#object[java.lang.Runtime$Version 0x781187fa &quot;11.0.2&quot;]
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12060/runtime-version-nested-class-jdk-not-automatically-imported</guid>
<pubDate>Thu, 21 Jul 2022 07:05:07 +0000</pubDate>
</item>
<item>
<title>Should other math wrappers be considered?</title>
<link>https://ask.clojure.org/index.php/11516/should-other-math-wrappers-be-considered</link>
<description>&lt;p&gt;With the &lt;code&gt;java.lang.Math&lt;/code&gt; operations all being wrapped, then is it also desirable to do the same with the operations static methods on &lt;code&gt;Double&lt;/code&gt; and &lt;code&gt;Long&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Some of these functions have simple Clojure(Script) implementations. For instance, &lt;code&gt;Double/isNaN&lt;/code&gt; can be achieved with &lt;code&gt;#(identical? ##NaN %)&lt;/code&gt; but it seems that if the language works with values like &lt;code&gt;##NaN&lt;/code&gt;, then there should be a built-in way of recognizing it. (I note that some people may not realize that &lt;code&gt;#(= ##NaN %)&lt;/code&gt; will not work).&lt;/p&gt;
&lt;p&gt;Each of these functions can also be implemented in ClojureScript. This was demonstrated while reimplementing the &lt;code&gt;clojure.math&lt;/code&gt; namespace for ClojureScript, since many of these methods from Long and Double were needed.&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11516/should-other-math-wrappers-be-considered</guid>
<pubDate>Wed, 26 Jan 2022 19:35:54 +0000</pubDate>
</item>
<item>
<title>Are there plans to implement JDK 1.8 interfaces?</title>
<link>https://ask.clojure.org/index.php/11464/are-there-plans-to-implement-jdk-1-8-interfaces</link>
<description>&lt;p&gt;With Clojure 1.10 moving to require Java 8, are there plans to implement any of the new interfaces that arrived in that version of Java?&lt;/p&gt;
&lt;p&gt;While not necessary to accomplish anything in Clojure, the interfaces in &lt;code&gt;java.util.function&lt;/code&gt; are sometimes necessary for interop. This requires clumsy wrapping with constructs like &lt;code&gt;reify&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For instance, &lt;code&gt;clojure.lang.AFn&lt;/code&gt; could be extended onto:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;BiFunction&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BiPredicate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Function&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Predicate&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With each implementing method calling the appropriate &lt;code&gt;invoke&lt;/code&gt; method. Clojure already uses &lt;code&gt;Object&lt;/code&gt; for most interop, so the generics would just use &lt;code&gt;Object&lt;/code&gt; everywhere.&lt;/p&gt;
&lt;p&gt;Some of the other interfaces could also be considered, casting arguments and results, though the type overloading of functions like &lt;code&gt;apply&lt;/code&gt; would limit what could be accomplished there.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11464/are-there-plans-to-implement-jdk-1-8-interfaces</guid>
<pubDate>Tue, 11 Jan 2022 15:46:20 +0000</pubDate>
</item>
<item>
<title>Apparently uncallable method overload</title>
<link>https://ask.clojure.org/index.php/10318/apparently-uncallable-method-overload</link>
<description>&lt;p&gt;Google Guava 30.1 defines these two addAll overloads for TreeRangeSet:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public void TreeRangeSet.addAll(RangeSet)
public default void RangeSet.addAll(Iterable&amp;lt;Range&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following compiles without error or warning:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(import [com.google.common.collect Range RangeSet TreeRangeSet])

(defn example []
  (let [container (TreeRangeSet/create)
        temp (TreeRangeSet/create ^Iterable (list (Range/closed 1 2)))]
     (.addAll container ^RangeSet temp)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, calling example fails with a runtime error stating that TreeRangeSet does not implement Iterable. As I understand it, this error happens because the Clojure compiler has emitted a call to the second overload (despite the type hint). After some experimenting, I believe this happens because the first overload returns true for isBridge; Reflector.getMethods will not return it since the second overload is not a bridge method.&lt;/p&gt;
&lt;p&gt;So two questions: is there a way to generate a call to the first overload, and, if not, should there be?&lt;/p&gt;
&lt;p&gt;(By the way, in initializing temp above, I wanted to use:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [temp (TreeRangeSet/create ^Iterable [(Range/closed 1 2)])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but this generates a reflection warning. I belive it is an example of CLJ-1929.)&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10318/apparently-uncallable-method-overload</guid>
<pubDate>Mon, 08 Mar 2021 19:53:18 +0000</pubDate>
</item>
<item>
<title>How to filter with embedded conversion?</title>
<link>https://ask.clojure.org/index.php/10221/how-to-filter-with-embedded-conversion</link>
<description>&lt;p&gt;I have some data, which I'm able to do a simple filter on:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn get-posts-body 
  []
  (:body @(client/get posts-url api-options)))

(defn get-books
  []
  (parse-string (get-books-body) true))

(defn get-non-fiction-books
  []
  (filter #(if (= &quot;non-fiction&quot; (:category %)) %) (get-books)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works well.&lt;/p&gt;
&lt;p&gt;I have another data source, posts, which I want to convert a field to a DateTime type and do a comparison on as well. Though it's not working:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defonce today (.withTimeAtStartOfDay (t/now)))

(defn get-posts-body 
  []
  (:body @(client/get posts-url api-options)))

(defn get-posts
  []
  (parse-string (get-posts-body) true))

(def get-posts-viewed-today
  []
  (filter #(if (&amp;gt;= (f/parse :date-time (:last_viewed_at %)) today) %) (get-posts)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I want all of the Maps which have a last_viewed_at DateTime &amp;gt;= to today.&lt;/p&gt;
&lt;p&gt;I'm trying to convert the String last_viewed_at to a DateTime and compare with today.&lt;/p&gt;
&lt;p&gt;It doesn't compile though:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Syntax error compiling def at (clojure_json_test/core.clj:46:1). Too&lt;br&gt;
many arguments to def&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Incidentially, I'm using:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(:require [clj-time.core :as t]
          [clj-time.format :as f]
          ;; ... )
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10221/how-to-filter-with-embedded-conversion</guid>
<pubDate>Sat, 20 Feb 2021 22:34:18 +0000</pubDate>
</item>
<item>
<title>Problem whilst requiring clojure clojure.data.csv :as csv</title>
<link>https://ask.clojure.org/index.php/10011/problem-whilst-requiring-clojure-clojure-data-csv-as-csv</link>
<description>&lt;p&gt;I'm learning clojure trought the book &quot;The Clojure Wokshop - Packt&quot; and i have stucked for a few days in this exercise:&lt;/p&gt;
&lt;p&gt;(My IDE is IntelliJ and i'm using Windows).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Exercise 4.10: Importing Data from a CSV File&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Create a folder somewhere convenient on your computer.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I decided to create an entirely new project given how many attempts i tried.&lt;/p&gt;
&lt;p&gt;Is there any difference here while choosing between Leiningen or Deps? I most of the time use Leiningen, but should i use Deps because i am gonna use a deps.edn file?&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/oPf6n.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Download the match_scores_1991-2016_UNINDEXED.csv file to the folder you created. (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/PacktWorkshops/The-Clojure-Workshop/tree/master/Chapter04/tennis-data&quot;&gt;here on github&lt;/a&gt;)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;But where should i download this file? Into the src file inside the project file or any file works? Is there any difference?&lt;/p&gt;
&lt;p&gt;I decided to save inside de src.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mupvy.png&quot; alt=&quot;print&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. In your editor, in the same folder, create a deps.edn file with the following contents:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:deps
 {org.clojure/data.csv {:mvn/version &quot;0.1.4&quot;}
  semantic-csv {:mvn/version &quot;0.2.1-alpha1&quot;}}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, i created a deps.edn file.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/BTGn8.png&quot; alt=&quot;deps.edn&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Verify that everything is working by evaluating the following expression in your REPL:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (require '[clojure.data.csv :as csv])
nil
user&amp;gt; (require '[clojure.java.io :as io])
nil
user&amp;gt; (with-open [r (io/reader &quot;match_scores_1991-2016_unindexed_csv.csv&quot;)]
         (first (csv/read-csv r)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When creating the REPL, should I select &quot;Run with Intellij project classpath&quot;, right? &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/1ZTvirB.png&quot; alt=&quot;https://i.imgur.com/1ZTvirB.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;But when i am gonna evaluate the testing expressions, it shows an error while evaluating the second one and third one.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/E4T30.png&quot; alt=&quot;error&quot;&gt;&lt;/p&gt;
&lt;p&gt;The error while evaluating the &quot;clojure.data.csv :as csv&quot; is this one:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error (FileNotFoundException) at csv-example.core/eval1549 (form-init2604783929697477049.clj:1).
Could not locate clojure/data/csv__init.class, clojure/data/csv.clj or clojure/data/csv.cljc on classpath.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What am i missing? Have been trying for days to solve this but i didn't found any answer.&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
</description>
<category>REPL</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10011/problem-whilst-requiring-clojure-clojure-data-csv-as-csv</guid>
<pubDate>Tue, 05 Jan 2021 21:25:07 +0000</pubDate>
</item>
<item>
<title>How to call reloadable Clojure from Java?</title>
<link>https://ask.clojure.org/index.php/9431/how-to-call-reloadable-clojure-from-java</link>
<description>&lt;p&gt;Given a Java application already having Clojure's &lt;code&gt;.jar&lt;/code&gt; on classpath. And a file directory &lt;code&gt;/home/me/clojure-extensions/&lt;/code&gt; which contains &lt;code&gt;.clj&lt;/code&gt; files, structured like an usual clojure source directory, which is not on the applications classpath and can not be added to the classpath, because it is configurable and not part of the application.&lt;/p&gt;
&lt;p&gt;How to call the function &lt;code&gt;myns.core/myfn&lt;/code&gt; from Java Code? So that &lt;code&gt;/home/me/clojure/extensions/myns/core.clj&lt;/code&gt; and all dependent files are loaded? So that these files are reloaded if changed when the Java call is invoked again?&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9431/how-to-call-reloadable-clojure-from-java</guid>
<pubDate>Thu, 09 Jul 2020 12:20:51 +0000</pubDate>
</item>
<item>
<title>What static type is needed to fix this &quot;Illegal reflective access&quot;?</title>
<link>https://ask.clojure.org/index.php/9377/what-static-type-needed-fix-this-illegal-reflective-access</link>
<description>&lt;p&gt;Attempting to get the length of a Unicode string, I found this code on RosettaCode &lt;strong&gt;[1]&lt;/strong&gt; called grapheme-length :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def grapheme-length
  #(-&amp;gt;&amp;gt; (doto (BreakIterator/getCharacterInstance)
          (.setText %))
        (partial (memfn next))
        repeatedly
        (take-while (partial not= BreakIterator/DONE))
        count))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I invoked it from the REPL to test it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(star-traders.util/grapheme-length &quot;\uD83D\uDE04⌘\uD83D\uDE00&quot;) ; Expecting 3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While it  &lt;em&gt;did&lt;/em&gt; return the expected value, I also got an unexpected warning in red text asking me to &quot;consider reporting this to the maintainers of clojure.lang.InjectedInvoker&quot;...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by clojure.lang.InjectedInvoker/0x0000000800cc8440 (file:/Users/myusername/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar) to method sun.text.RuleBasedBreakIterator.setText(java.text.CharacterIterator)
WARNING: Please consider reporting this to the maintainers of clojure.lang.InjectedInvoker/0x0000000800cc8440
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Apparently this is a known issue with the JVM due to the addition of the Java 9 module system and is mentioned in the Clojure FAQ. &lt;strong&gt;[2]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While the problem &lt;em&gt;does&lt;/em&gt; go away if &lt;code&gt;--illegal-access=deny&lt;/code&gt; is added to the JVM Args, it appears that the recommended solution is to fix the code with type hinting.&lt;/p&gt;
&lt;p&gt;I've tried using &lt;code&gt;--illegal-access=warn&lt;/code&gt; to locate the spot and fix it, like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;          (.setText ^java.text.BreakIterator %)) ; Problem happens here (I think)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, the problem still occurs, and this has me curious what the right type I should be using is. &lt;/p&gt;
&lt;p&gt;How do I fix the code to get rid of the compiler warning, rather than suppress warnings?&lt;/p&gt;
&lt;p&gt;[1] &lt;a rel=&quot;nofollow&quot; href=&quot;https://rosettacode.org/wiki/String_length#Grapheme_Length_2&quot;&gt;https://rosettacode.org/wiki/String_length#Grapheme_Length_2&lt;/a&gt;&lt;br&gt;
[2] &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/guides/faq#illegal_access&quot;&gt;https://clojure.org/guides/faq#illegal_access&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9377/what-static-type-needed-fix-this-illegal-reflective-access</guid>
<pubDate>Wed, 10 Jun 2020 02:24:56 +0000</pubDate>
</item>
<item>
<title>Reading serialized Java Objects in Clojure</title>
<link>https://ask.clojure.org/index.php/9369/reading-serialized-java-objects-in-clojure</link>
<description>&lt;p&gt;Hello everyone,&lt;/p&gt;
&lt;p&gt;I have a lot of Java Serialized Objects I wish to inspect and transform.&lt;/p&gt;
&lt;p&gt;I tried using the naive Java-in-Clojure way to do the following:&lt;br&gt;
(Excuse the iterative style, I'm usually never interfacing with Java directly and it's also a language I'm relatively unfamiliar with, but this doesn't seem to have a clojuristic wrapper.&lt;/p&gt;
&lt;p&gt;file that contains object: input.ser&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(import '[java.io FileInputStream ObjectInputStream])
(def fis (new FileInputStream &quot;input.ser&quot;))
(def ois (new ObjectInputStream fis)

(.readObject ois) ;; this fails due to a ClassNotFoundException
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there a way to get the &lt;em&gt;sort-of&lt;/em&gt; Deserialized View of the object that I can inspect after loading? The file itself is unreadable because it compresses the bytes before serializing.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9369/reading-serialized-java-objects-in-clojure</guid>
<pubDate>Fri, 05 Jun 2020 14:04:33 +0000</pubDate>
</item>
<item>
<title>How to call java method with interface as parameters?</title>
<link>https://ask.clojure.org/index.php/9296/how-to-call-java-method-with-interface-as-parameters</link>
<description>&lt;p&gt;Here's my sample code.&lt;br&gt;
Thanks.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Java code
interface IFace {
  String message();
}
class A implements IFace {
  @Override message () { return &quot;Hello A!&quot;};
}
class B implements IFace {
  @Override message () { return &quot;Hello B!&quot;};
}
class PrintHello {
  static void print (IFace msg) {
    if (msg instanceof A) { ... } else { ... }
  }
}

; Clojure code

(def a (A.))
(. PrintHello (print a))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9296/how-to-call-java-method-with-interface-as-parameters</guid>
<pubDate>Fri, 08 May 2020 04:37:31 +0000</pubDate>
</item>
<item>
<title>Failure using Clojure code in plugin for Java framework (KSQL)</title>
<link>https://ask.clojure.org/index.php/8876/failure-using-clojure-code-in-plugin-for-java-framework-ksql</link>
<description>&lt;p&gt;I'm trying to write a user-defined function for KSQL in Clojure. KSQL wants you to give it an uberjar with an annotated java class. I've tried this with both gen-class and a hand-authored java file that interops to Clojure. In both cases, the uberjar gets loaded fine, and my class annotations are detected via reflection. But I get exceptions like &quot;java.lang.ExceptionInInitializerError&quot; and &quot;java.lang.NoClassDefFoundError: Could not initialize class clojure.java.api.Clojure&quot; as soon as anything to do with clojure is executed, like Clojure.var(&quot;clojure.core&quot;, &quot;require&quot;)  Feels like I must be missing something about how the uberjar needs to be built. Or perhaps this is a classloader issue. KSQL apparently does some kind of classpath isolation to keep user-defined functions from stepping on each other.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8876/failure-using-clojure-code-in-plugin-for-java-framework-ksql</guid>
<pubDate>Fri, 22 Nov 2019 22:05:46 +0000</pubDate>
</item>
<item>
<title>Declare an interface with gen-interface that throws an Exception ?</title>
<link>https://ask.clojure.org/index.php/8738/declare-interface-with-gen-interface-that-throws-exception</link>
<description>&lt;p&gt;I'm trying to replicate a Java interface using gen-interface, which has some Java classes implementing it where they define their overrides as &lt;code&gt;throws Exception&lt;/code&gt;. But I do not know how in Clojure to specify that in the signature?&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class Someclass implements MyInterface {
  public void perform(CommandLine line) throws Exception {
     ...
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;-&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(gen-interface
 :name some.place.MyInterface
 :methods [[perform [org.apache.commons.cli.CommandLine] void]])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This fails with in javac with: &lt;code&gt;overridden method does not throw Exception&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Is there any way to create an interface which declares a throws clause on the methods in Clojure using gen-interface?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8738/declare-interface-with-gen-interface-that-throws-exception</guid>
<pubDate>Sat, 19 Oct 2019 01:15:07 +0000</pubDate>
</item>
</channel>
</rss>