<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions in Java Interop</title>
<link>https://ask.clojure.org/index.php/questions/clojure/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>definterface doesn't expose gen-interface's :extends for interface extension</title>
<link>https://ask.clojure.org/index.php/14903/definterface-doesnt-interfaces-extends-interface-extension</link>
<description>&lt;p&gt;gen-interface allow :extends to specify one or more interfaces, which will be extended by this interface. &lt;/p&gt;
&lt;p&gt;definterface doesn't expose this.&lt;/p&gt;
&lt;p&gt;Use case is working with primitives (where protocols don’t help), to get things to dispatch nicely in a zero boxing primitive transducer implementation.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14903/definterface-doesnt-interfaces-extends-interface-extension</guid>
<pubDate>Mon, 26 Jan 2026 19:49:08 +0000</pubDate>
</item>
<item>
<title>clojure.core/subs should use type hints of ^CharSequence, NOT ^String</title>
<link>https://ask.clojure.org/index.php/14889/clojure-core-subs-should-use-type-hints-charsequence-string</link>
<description>&lt;p&gt;This is related to &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/4616/clojure-interfaces-specify-charsequence-instead-possible&quot;&gt;this ancient ask&lt;/a&gt;, but it would be ideal if &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.core/subs&quot;&gt;&lt;code&gt;clojure.core/subs&lt;/code&gt;&lt;/a&gt; was type hinted with &lt;code&gt;^CharSequence&lt;/code&gt; rather than &lt;code&gt;^String&lt;/code&gt;, and used the &lt;code&gt;subSequence()&lt;/code&gt; method instead of &lt;code&gt;substring()&lt;/code&gt; (since the latter doesn't exist in &lt;code&gt;CharSequence&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The single parameter version of &lt;code&gt;subs&lt;/code&gt; would need to call &lt;code&gt;s.length()&lt;/code&gt; as the second argument in the call to &lt;code&gt;subSequence()&lt;/code&gt; (there is no single-arg version of that method, unlike &lt;code&gt;substring()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;More generally, there are substantial benefits in using &lt;code&gt;CharSequence&lt;/code&gt; instead of &lt;code&gt;String&lt;/code&gt; throughout Clojure core, not only in the context of Java interop, but also when using custom String-like data structures (e.g. &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/IGJoshua/ropes&quot;&gt;ropes&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;[edit] @alexmiller mentioned this in another forum (and I'm capturing it here for posterity), but this might also require that the result be &lt;code&gt;str&lt;/code&gt;ed, to ensure the return type remains unchanged (&lt;code&gt;subSequence()&lt;/code&gt; returns a &lt;code&gt;CharSequence&lt;/code&gt;, unlike &lt;code&gt;substring&lt;/code&gt;, which might break callers).  There may be performance implications of adding that call for types other than &lt;code&gt;String&lt;/code&gt; (but existing callers should be unaffected, since &lt;code&gt;String.toString()&lt;/code&gt; is identity).&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14889/clojure-core-subs-should-use-type-hints-charsequence-string</guid>
<pubDate>Tue, 13 Jan 2026 18:10:48 +0000</pubDate>
</item>
<item>
<title>Could we get deref support on ScopedValue?</title>
<link>https://ask.clojure.org/index.php/14771/could-we-get-deref-support-on-scopedvalue</link>
<description>&lt;p&gt;Following on from &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/14767/multiple-cannot-idiomatically-leveraged-proper-ideref-support&quot;&gt;this&lt;/a&gt;, and since &lt;code&gt;Optional&lt;/code&gt; is already being considered, I would like to propose that &lt;code&gt;ScopedValue&lt;/code&gt; is considered as well. It is now a standard feature on an LTS release (i.e. 25).&lt;/p&gt;
&lt;p&gt;As always, thanks in advance...&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14771/could-we-get-deref-support-on-scopedvalue</guid>
<pubDate>Tue, 25 Nov 2025 16:26:47 +0000</pubDate>
</item>
<item>
<title>Multiple Java types cannot be idiomatically leveraged w/o proper `IDeref` support</title>
<link>https://ask.clojure.org/index.php/14767/multiple-cannot-idiomatically-leveraged-proper-ideref-support</link>
<description>&lt;p&gt;There are certain java types that are a perfect fit for &lt;code&gt;IDeref&lt;/code&gt; - e.g. &lt;code&gt;Optional&lt;/code&gt;, &lt;code&gt;ScopedValue&lt;/code&gt;, &lt;code&gt;LazyConstant&lt;/code&gt; etc. However, since &lt;code&gt;IDeref&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; a protocol (like in &lt;code&gt;cljs&lt;/code&gt;), we are left with having to ask for this to be added/supported (e.g. &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2905&quot;&gt;this&lt;/a&gt;) every time.  I guess my question is whether it is at all feasible to have &lt;code&gt;IDeref be a protocol&lt;/code&gt;, and if not, what are the plans (if any) for supporting &lt;code&gt;deref&lt;/code&gt; on these types? &lt;/p&gt;
&lt;p&gt;Many thanks in advance...   &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14767/multiple-cannot-idiomatically-leveraged-proper-ideref-support</guid>
<pubDate>Mon, 24 Nov 2025 17:33:52 +0000</pubDate>
</item>
<item>
<title>Improve javadoc especially for tool usage</title>
<link>https://ask.clojure.org/index.php/14715/improve-javadoc-especially-for-tool-usage</link>
<description>&lt;p&gt;In order to provide a hot key in VS Code to show the JavaDocs associated with a selected form (class name or the type of an expression), I wrote the following Joyride script:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/seancorfield/vscode-calva-setup/blob/develop/joyride/scripts/javadoc.cljs#L15&quot;&gt;https://github.com/seancorfield/vscode-calva-setup/blob/develop/joyride/scripts/javadoc.cljs#L15&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This highlights three issues that could be addressed/improved:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On JDKs later than 15, the javadoc machinery falls back to JDK 8, unless you explicitly call &lt;code&gt;add-remote-javadoc&lt;/code&gt; for at least &lt;code&gt;java.&lt;/code&gt; and &lt;code&gt;javax.&lt;/code&gt;. This is a known issue that should be addressed in Clojure 1.13 per &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2920&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2920&lt;/a&gt; -- hopefully it will assume the URL structure for JDKs going forward so we don't run into this problem again, unless Oracle changes their URL structure again (hopefully, unlikely).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;javadoc-url&lt;/code&gt; is private so tools have to use &lt;code&gt;#'&lt;/code&gt; to access it, which makes it feel like this is just an implementation detail and subject to change. It would be nice for tools if this was part of the public, documented API for &lt;code&gt;clojure.java.javadoc&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inner classes are not handled well. If you ask for the &lt;code&gt;javadoc-url&lt;/code&gt; for &lt;code&gt;java.util.Map$Entry&lt;/code&gt;, you get a URL with &lt;code&gt;Map$Entry.html&lt;/code&gt; which doesn't exist. Since inner classes are documented in their outer class, removing &lt;code&gt;$[a-zA-Z0-9_]+&lt;/code&gt; from the class name or from the URL would really help here.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here's an example REPL session for Clojure 1.12.2 on JDK 24, showing these issues:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;user=&amp;gt; (clojure-version)
&quot;1.12.2&quot;
user=&amp;gt; (require 'clojure.java.javadoc)
nil
user=&amp;gt; (#'clojure.java.javadoc/javadoc-url &quot;java.util.concurrent.ExecutionException&quot;)
&quot;http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutionException.html&quot;
user=&amp;gt; (#'clojure.java.javadoc/javadoc-url &quot;java.util.Map$Entry&quot;)
&quot;http://docs.oracle.com/javase/8/docs/api/java/util/Map$Entry.html&quot;
user=&amp;gt; &lt;/code&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14715/improve-javadoc-especially-for-tool-usage</guid>
<pubDate>Tue, 16 Sep 2025 17:54:13 +0000</pubDate>
</item>
<item>
<title>Refection warning even with type hinting</title>
<link>https://ask.clojure.org/index.php/14622/refection-warning-even-with-type-hinting</link>
<description>&lt;p&gt;I have the function&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn println-err [^String s]
  (.println *err* s))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I set &lt;code&gt;*warn-on-reflections*&lt;/code&gt;, I get&lt;br&gt;
&amp;gt; call to method println can't be resolved (target class is unknown).&lt;/p&gt;
&lt;p&gt;I can work around this with &lt;code&gt;(binding [*out* *err*] (println s)))&lt;/code&gt;, but I'd like to know why I'm getting this reflection warning even though I'm telling the compiler the type.&lt;/p&gt;
&lt;p&gt;Note: I have zero Java experience.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14622/refection-warning-even-with-type-hinting</guid>
<pubDate>Fri, 11 Jul 2025 14:48:42 +0000</pubDate>
</item>
<item>
<title>Method with int parameter is called, although the provided parameter is long</title>
<link>https://ask.clojure.org/index.php/14612/method-with-parameter-called-although-provided-parameter</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/LWJGL/lwjgl3/blob/3.3.6/modules/lwjgl/assimp/src/generated/java/org/lwjgl/assimp/AIMesh.java&quot;&gt;AIMesh&lt;/a&gt; provides several overloaded &lt;code&gt;create&lt;/code&gt; methods. There is one with an &lt;code&gt;int&lt;/code&gt; parameter and another one with a &lt;code&gt;long&lt;/code&gt; parameter. They have very different semantics.&lt;/p&gt;
&lt;p&gt;This code snippet intends to call the one with the &lt;code&gt;long&lt;/code&gt; parameter:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn read-model
  &quot;read a 3D model from a file&quot;
  [path]
  (let [scene (Assimp/aiImportFile path (bit-or Assimp/aiProcess_Triangulate
                                                Assimp/aiProcess_FlipUVs))]
    (if (= scene nil)
      (println (Assimp/aiGetErrorString))
      (for [index (range (.mNumMeshes scene))]
        (let [pointer (.get (.mMeshes scene) index)]
          (assert (= (type pointer) java.lang.Long))
          (AIMesh/create pointer))))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The assertion right before the problematic call makes sure that &lt;code&gt;pointer&lt;/code&gt; is indeed a &lt;code&gt;long&lt;/code&gt;; but nevertheless the &lt;code&gt;int&lt;/code&gt; overload of &lt;code&gt;create&lt;/code&gt; is called, as can be verified in the stack trace:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:clojure.main/message
 &quot;Execution error (IllegalArgumentException) at java.nio.Buffer/createCapacityException (Buffer.java:290).\ncapacity &amp;lt; 0: (-689151616 &amp;lt; 0)\n&quot;,
 :clojure.main/triage
 {:clojure.error/class java.lang.IllegalArgumentException,
  :clojure.error/line 290,
  :clojure.error/cause &quot;capacity &amp;lt; 0: (-689151616 &amp;lt; 0)&quot;,
  :clojure.error/symbol java.nio.Buffer/createCapacityException,
  :clojure.error/source &quot;Buffer.java&quot;,
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.Compiler$CompilerException,
    :message
    &quot;Syntax error macroexpanding at (learnopengl/core.clj:12:1).&quot;,
    :data
    {:clojure.error/phase :execution,
     :clojure.error/line 12,
     :clojure.error/column 1,
     :clojure.error/source &quot;learnopengl/core.clj&quot;},
    :at [clojure.lang.Compiler load &quot;Compiler.java&quot; 7665]}
   {:type java.lang.IllegalArgumentException,
    :message &quot;capacity &amp;lt; 0: (-689151616 &amp;lt; 0)&quot;,
    :at [java.nio.Buffer createCapacityException &quot;Buffer.java&quot; 290]}],
  :trace
  [[java.nio.Buffer createCapacityException &quot;Buffer.java&quot; 290]
   [java.nio.Buffer &amp;lt;init&amp;gt; &quot;Buffer.java&quot; 253]
   [java.nio.ByteBuffer &amp;lt;init&amp;gt; &quot;ByteBuffer.java&quot; 316]
   [java.nio.ByteBuffer &amp;lt;init&amp;gt; &quot;ByteBuffer.java&quot; 324]
   [java.nio.MappedByteBuffer &amp;lt;init&amp;gt; &quot;MappedByteBuffer.java&quot; 113]
   [java.nio.DirectByteBuffer &amp;lt;init&amp;gt; &quot;DirectByteBuffer.java&quot; 107]
   [java.nio.ByteBuffer allocateDirect &quot;ByteBuffer.java&quot; 360]
   [org.lwjgl.system.Struct __create &quot;Struct.java&quot; 118]
   [org.lwjgl.assimp.AIMesh create &quot;AIMesh.java&quot; 487]
   [jdk.internal.reflect.DirectMethodHandleAccessor
    invoke
    &quot;DirectMethodHandleAccessor.java&quot;
    103]
   [java.lang.reflect.Method invoke &quot;Method.java&quot; 580]
   [clojure.lang.Reflector invokeMatchingMethod &quot;Reflector.java&quot; 167]
   [clojure.lang.Reflector invokeStaticMethod &quot;Reflector.java&quot; 332]
   [learnopengl.mesh_model$read_model$iter__332__336$fn__337$fn__338
    invoke
    &quot;mesh_model.clj&quot;
    66]
   [learnopengl.mesh_model$read_model$iter__332__336$fn__337
    invoke
    &quot;mesh_model.clj&quot;
    63]
   [clojure.lang.LazySeq sval &quot;LazySeq.java&quot; 42]
   [clojure.lang.LazySeq seq &quot;LazySeq.java&quot; 51]
   [clojure.lang.RT seq &quot;RT.java&quot; 535]
   [clojure.lang.RT countFrom &quot;RT.java&quot; 650]
   [clojure.lang.RT count &quot;RT.java&quot; 643]
   [learnopengl.core$eval351 invokeStatic &quot;core.clj&quot; 12]
   [learnopengl.core$eval351 invoke &quot;core.clj&quot; 12]
   [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7194]
   [clojure.lang.Compiler load &quot;Compiler.java&quot; 7653]
   [clojure.lang.RT loadResourceScript &quot;RT.java&quot; 381]
   [clojure.lang.RT loadResourceScript &quot;RT.java&quot; 372]
   [clojure.lang.RT load &quot;RT.java&quot; 459]
   [clojure.lang.RT load &quot;RT.java&quot; 424]
   [clojure.core$load$fn__6908 invoke &quot;core.clj&quot; 6161]
   [clojure.core$load invokeStatic &quot;core.clj&quot; 6160]
   [clojure.core$load doInvoke &quot;core.clj&quot; 6144]
   [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 408]
   [clojure.core$load_one invokeStatic &quot;core.clj&quot; 5933]
   [clojure.core$load_one invoke &quot;core.clj&quot; 5928]
   [clojure.core$load_lib$fn__6850 invoke &quot;core.clj&quot; 5975]
   [clojure.core$load_lib invokeStatic &quot;core.clj&quot; 5974]
   [clojure.core$load_lib doInvoke &quot;core.clj&quot; 5953]
   [clojure.lang.RestFn applyTo &quot;RestFn.java&quot; 142]
   [clojure.core$apply invokeStatic &quot;core.clj&quot; 669]
   [clojure.core$load_libs invokeStatic &quot;core.clj&quot; 6016]
   [clojure.core$load_libs doInvoke &quot;core.clj&quot; 6000]
   [clojure.lang.RestFn applyTo &quot;RestFn.java&quot; 137]
   [clojure.core$apply invokeStatic &quot;core.clj&quot; 669]
   [clojure.core$require invokeStatic &quot;core.clj&quot; 6038]
   [clojure.core$require doInvoke &quot;core.clj&quot; 6038]
   [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 408]
   [user$eval140$fn__144 invoke &quot;form-init15974239925031016013.clj&quot; 1]
   [user$eval140 invokeStatic &quot;form-init15974239925031016013.clj&quot; 1]
   [user$eval140 invoke &quot;form-init15974239925031016013.clj&quot; 1]
   [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7194]
   [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7184]
   [clojure.lang.Compiler load &quot;Compiler.java&quot; 7653]
   [clojure.lang.Compiler loadFile &quot;Compiler.java&quot; 7591]
   [clojure.main$load_script invokeStatic &quot;main.clj&quot; 475]
   [clojure.main$init_opt invokeStatic &quot;main.clj&quot; 477]
   [clojure.main$init_opt invoke &quot;main.clj&quot; 477]
   [clojure.main$initialize invokeStatic &quot;main.clj&quot; 508]
   [clojure.main$null_opt invokeStatic &quot;main.clj&quot; 542]
   [clojure.main$null_opt invoke &quot;main.clj&quot; 539]
   [clojure.main$main invokeStatic &quot;main.clj&quot; 664]
   [clojure.main$main doInvoke &quot;main.clj&quot; 616]
   [clojure.lang.RestFn applyTo &quot;RestFn.java&quot; 137]
   [clojure.lang.Var applyTo &quot;Var.java&quot; 705]
   [clojure.main main &quot;main.java&quot; 40]],
  :cause &quot;capacity &amp;lt; 0: (-689151616 &amp;lt; 0)&quot;,
  :phase :execution}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/cyberdynesoftware/learnopengl/commit/6e0943c11d51a46591dbdd716f4216247aef9ba3&quot;&gt;repository&lt;/a&gt; contains the full code to reproduce the error. &lt;code&gt;read-model&lt;/code&gt; is defined in mesh-model.clj.&lt;/p&gt;
&lt;p&gt;I ran this with Clojure version 1.11.1 and Java version:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;openjdk 21.0.7 2025-04-15
OpenJDK Runtime Environment (Red_Hat-21.0.7.0.6-2) (build 21.0.7+6)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.7.0.6-2) (build 21.0.7+6, mixed mode, sharing)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There was a previous question on &lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/questions/79689152/reading-a-3d-model-with-lwjgl-assimp-failes-in-clojure&quot;&gt;stackoverflow&lt;/a&gt; leading to this question.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14612/method-with-parameter-called-although-provided-parameter</guid>
<pubDate>Sat, 05 Jul 2025 21:13:00 +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>Default Imports Don't Include Clojure Internals</title>
<link>https://ask.clojure.org/index.php/14586/default-imports-dont-include-clojure-internals</link>
<description>&lt;p&gt;The map &lt;code&gt;clojure.lang.RT/DEFAULT_IMPORTS&lt;/code&gt; defines all of the Java classes that are (by default) available in all Clojure namespaces. In 2007, Rich added and then commented out a number of the &lt;code&gt;clojure.lang&lt;/code&gt; classes and interfaces (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/commit/46e575bc17e5e54948b4f378973f69266a69ea07&quot;&gt;removed in this commit&lt;/a&gt;) without any commentary, and those lines have remained unchanged since.&lt;/p&gt;
&lt;p&gt;Is there a reason why the &quot;primary&quot; &lt;code&gt;clojure.lang&lt;/code&gt; classes and interfaces aren't imported by default?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14586/default-imports-dont-include-clojure-internals</guid>
<pubDate>Tue, 24 Jun 2025 14:02:08 +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>Using java.data</title>
<link>https://ask.clojure.org/index.php/14490/using-java-data</link>
<description>&lt;p&gt;Hi @here,&lt;br&gt;
Clojure noob and java dev here. &lt;br&gt;
Wanted to convert a tree object into clojure object. This is not the definite end goal.&lt;/p&gt;
&lt;p&gt;Aim is to provide a human readable intermediate language that will have parameterized methods for similar subtrees that will provide lazy initialization for breadth first search from root. (Not a proper BFS, you have expand and create objects for all children and when a node is selected among children, you have to get all its children. So, more like, expand all nodes, select a node, repeat)&lt;/p&gt;
&lt;p&gt;This will again output a data format like yaml.&lt;/p&gt;
&lt;p&gt;When I tried to do traversal in the clojure with java.data lib, it threw error because the objects were not pure java beans. So, I plugged into the name space and changed a method definition to use reflection instead of getter, setters.&lt;/p&gt;
&lt;p&gt;Then it was working for simple cases but even slightly large case, I am getting stack overflow error. Is that normal? &lt;br&gt;
I did not create the intermediate language in clojure yet, I just created the object and tried to convert.&lt;br&gt;
I increased the stack memory, still I was not able to solve this.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14490/using-java-data</guid>
<pubDate>Wed, 02 Apr 2025 15:55:56 +0000</pubDate>
</item>
<item>
<title>SourceDataLine method not found</title>
<link>https://ask.clojure.org/index.php/14351/sourcedataline-method-not-found</link>
<description>&lt;p&gt;Hi, I've found some weird behaviour when attempting to play a sound using a &lt;code&gt;javax.sound.sampled.SourceDataLine&lt;/code&gt;. The following code illustrates the problem:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns cljtest.core)
(import '[java.util Random]
        '[javax.sound.sampled AudioSystem AudioFormat])

; create an AudioFormat instance:
(def fmt (AudioFormat. 44100. 16 2 true false))

; create some data representing a second of white noise:
(def data (byte-array 176400))
(.nextBytes (Random.) data)

; define a function that creates a SourceDataLine and uses it to play a sound:
(defn play1 []
  (let [l (AudioSystem/getSourceDataLine fmt)]
    (.open l) (.start l) (.write l data 0 (count data))))

; define a function that creates a SourceDataLine and returns it:
(defn getline []
  (AudioSystem/getSourceDataLine fmt))

; define a function that uses the output of getline to play a sound:
(defn play2 []
  (let [l (getline)]
    (.open l) (.start l) (.write l data 0 (count data))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compiling this with Clojure 1.12.0 using Leiningen, &lt;code&gt;play1&lt;/code&gt; does what it's supposed to, but &lt;code&gt;play2&lt;/code&gt; gives me the following error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error (IllegalArgumentException) at cljtest.core/play2 (core.clj:24).
No matching method write found taking 3 args for class com.sun.media.sound.DirectAudioDevice$DirectSDL
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I get this error using both OpenJDK 21.0.5.11-hotspot and Oracle's JDK 23. Also with Clojure 1.11.0 and 1.10.0, but 1.9.0 works fine. Anyone know why this is happening?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14351/sourcedataline-method-not-found</guid>
<pubDate>Wed, 22 Jan 2025 21:38:08 +0000</pubDate>
</item>
<item>
<title>Java interop issue</title>
<link>https://ask.clojure.org/index.php/14240/java-interop-issue</link>
<description>&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;Failing to make clojure work with our commercial java library. I can run the following Java code on my machine and it works fine: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import com.numerix.pro.Application;
import com.numerix.pro.ApplicationCall;
import com.numerix.pro.ApplicationData;
import com.numerix.pro.ApplicationObjectFactory;
import com.numerix.pro.ApplicationWarning;

public final class FxAmericanOption {

    public static void main(final String argv[]) 
    {
        int rVal = 0;      // exit value
        try {
            System.out.println(&quot;Running: &quot; + new Throwable().getStackTrace()[0].getClassName() + &quot;\n&quot;);

            final Application app = new Application();
            {
                final ApplicationCall call = new ApplicationCall();
                call.addValue(&quot;ID&quot;,       &quot;USD_Curve&quot;);
                call.addValue(&quot;OBJECT&quot;,   &quot;Curve&quot;);
                call.addValue(&quot;TYPE&quot;,     &quot;Yield&quot;);
                call.addValue(&quot;Now Date&quot;, ApplicationObjectFactory.parseDate(&quot;26-Oct-2003&quot;));
                call.addValue(&quot;CURRENCY&quot;, &quot;USD&quot;);
                call.addValue(&quot;RATE&quot;,     0.04);

                final String[] outHeaders =
                    new String[] {&quot;Updated&quot;, &quot;Timer&quot;, &quot;ID&quot;};

                final ApplicationWarning warning = new ApplicationWarning();

                app.call(call, outHeaders, warning);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I tried porting it to clojure 1.12 like this &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns hello
  (:import (com.numerix.pro Application ApplicationCall
                            ApplicationWarning 
                            ApplicationObjectFactory)))
           
(def myapp (new Application))
(def appcall (new ApplicationCall))
(def warning (new ApplicationWarning))

(.addValue ^ApplicationCall appcall &quot;NAME&quot; &quot;Yield Curve&quot;)
(.addValue ^ApplicationCall appcall &quot;ID&quot; &quot;MyCurve&quot;)
(.addValue ^ApplicationCall appcall &quot;OBJECT&quot; &quot;Curve&quot;)
(.addValue ^ApplicationCall appcall &quot;TYPE&quot; &quot;Yield&quot;)
(.addValue ^ApplicationCall appcall &quot;Now Date&quot; (ApplicationObjectFactory/parseDate &quot;26-Oct-2023&quot;))
(.addValue ^ApplicationCall appcall &quot;CURRENCY&quot; &quot;USD&quot;)
(.addValue ^ApplicationCall appcall &quot;RATE&quot; 0.04)

(def outHeaders (into-array String [&quot;timer&quot; &quot;id&quot;]))

(^[ApplicationCall String/1 ApplicationWarning] Application/.call ^Application myapp
                                                                  ^ApplicationCall appcall
                                                                  ^String/1 outHeaders
                                                                  ^ApplicationWarning warning)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can inspect appcall object and it looks totally fine - all the .addValue register correctly with it. But when I evaluate the last form with Application/.call I get an error which I don't understand how to address.. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt; Execution error (IllegalAccessError) at hello/eval10370 (REPL:25).
; failed to access class com.numerix.pro.ApplicationCommon from class hello$eval10370 (com.numerix.pro.ApplicationCommon is in unnamed module of loader 'app'; hello$eval10370 is in unnamed module of loader clojure.lang.DynamicClassLoader @cc01572)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any help much appreciated! &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14240/java-interop-issue</guid>
<pubDate>Tue, 12 Nov 2024 19:25:31 +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>Wrong implementation of IBlockingDeref for clojure.java.process/start</title>
<link>https://ask.clojure.org/index.php/13990/wrong-implementation-iblockingderef-clojure-process-start</link>
<description>&lt;p&gt;The &lt;code&gt;IBlockingDeref&lt;/code&gt; for the reification in clojure.java.process/start is not implemented according to specification in &lt;code&gt;deref&lt;/code&gt; doc-string.&lt;/p&gt;
&lt;p&gt;The 3-arity &lt;code&gt;IBlockingDeref&lt;/code&gt; expects &lt;code&gt;timeout&lt;/code&gt; in milliseconds, and that the third argument is a &lt;code&gt;timeout-val&lt;/code&gt;. The implementation in &lt;code&gt;clojure.java.process&lt;/code&gt; (line 113, linked below) wrongly expects the two arguments to be a timeout with its unit specified in last argument as a &lt;code&gt;java.util.concurrent.TimeUnit&lt;/code&gt;. When given some j.u.c.TimeUnit as &lt;code&gt;timeout-val&lt;/code&gt;, it will still return &lt;code&gt;nil&lt;/code&gt; after the timeout.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Expected:&lt;/strong&gt; That this implementation of IBlockingDeref always assumes the timeunit to be hardcoded as TimeUnit/MILLISECONDS, and that the given &lt;code&gt;timeout-val&lt;/code&gt; is returned if the deref to IBlockingDeref times out.&lt;/p&gt;
&lt;p&gt;See &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/aa2c637f9512d14bd78ee30d6d030bba6d095e7d/src/clj/clojure/java/process.clj#L113&quot;&gt;clojure/java/process.clj#L113&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13990/wrong-implementation-iblockingderef-clojure-process-start</guid>
<pubDate>Tue, 25 Jun 2024 12:59:18 +0000</pubDate>
</item>
<item>
<title>Request: def should infer type tag where possible</title>
<link>https://ask.clojure.org/index.php/13872/request-def-should-infer-type-tag-where-possible</link>
<description>&lt;p&gt;Maybe there’s a good reason why it doesn’t, but it seems to me it would be great if def would automatically infer type hint:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [s &quot;abc&quot;]
  (.chars s)) ;; all fine, no warning

(def s &quot;abc&quot;)

(.chars s) ;; Reflection warning, null:21:0 - reference to field chars can't be resolved.

(meta #'s) ;; ↓ notice -- no tag
;; {:line 19,
;;  :column 0,
;;  :file &quot;NO_SOURCE_FILE&quot;,
;;  :name s,
;;  :ns #object[clojure.lang.Namespace 0x78068afb &quot;user&quot;]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Related jira: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2851&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2851&lt;/a&gt;&lt;br&gt;
Related question: &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/9167/infer-hint-from-return-type-hint-function-call-initializes&quot;&gt;https://ask.clojure.org/index.php/9167/infer-hint-from-return-type-hint-function-call-initializes&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13872/request-def-should-infer-type-tag-where-possible</guid>
<pubDate>Fri, 03 May 2024 20:01:21 +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>`resolve` should support array class symbols?</title>
<link>https://ask.clojure.org/index.php/13674/resolve-should-support-array-class-symbols</link>
<description>&lt;p&gt;Clojure 1.12.0-alpha6 has introduced array class symbols, but it doesn't seem that &lt;code&gt;resolve&lt;/code&gt; supports them right now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(resolve 'long**) ;=&amp;gt; nil
(resolve 'String**) ;=&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It would be nice if &lt;code&gt;resolve&lt;/code&gt; would be aware of array class symbols. Otherwise, it'd require extra work for some sorts of macros and development tools (that use &lt;code&gt;resolve&lt;/code&gt; under the hood) to support them.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13674/resolve-should-support-array-class-symbols</guid>
<pubDate>Fri, 09 Feb 2024 02:06:42 +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>Add support for context logging in tools.logging</title>
<link>https://ask.clojure.org/index.php/13491/add-support-for-context-logging-in-tools-logging</link>
<description>&lt;p&gt;Structured logging beats plain text.&lt;br&gt;
Context logging + structured logging is a net win. At my workplace we could dump our ad-hoc logging solution which besides support for context logging is inferior to tools.logging, and will make a strong addition to the library's capabilities.&lt;br&gt;
To add support for context logging, we'll probably need an additional protocol for the frameworks which implement such APIs (like SLF4J).&lt;br&gt;
Not sure if it's required, but an additional logging function might also simplify the implementation.&lt;br&gt;
Suggested usage:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(log/info-c {:foo &quot;bar&quot;} my-error &quot;some message&quot;)
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13491/add-support-for-context-logging-in-tools-logging</guid>
<pubDate>Sun, 26 Nov 2023 16:21:19 +0000</pubDate>
</item>
<item>
<title>RT/chunkIteratorSeq does not produce a chunked-seq?</title>
<link>https://ask.clojure.org/index.php/13471/rt-chunkiteratorseq-does-not-produce-a-chunked-seq</link>
<description>&lt;pre&gt;&lt;code&gt;user&amp;gt; (def al (hamf/array-list (range 200))) 
#'user/al
user&amp;gt; (type al)
java.util.ArrayList
user&amp;gt; (chunked-seq? (seq al))
false
user&amp;gt; (instance? java.lang.Iterable al)
trueSyntax error reading source at (REPL:65:41).
Unmatched delimiter: )
user&amp;gt; (instance? java.lang.Iterable al)
true
user&amp;gt; (chunked-seq? (clojure.lang.RT/seq al))
false
user&amp;gt; (chunked-seq? (clojure.lang.RT/chunkIteratorSeq (.iterator al)))
false
user&amp;gt; (type (clojure.lang.RT/chunkIteratorSeq (.iterator al)))
clojure.lang.LazySeq
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If no lazy seq is a chunked seq then the result of clojure.core/map, filter, etc. also cannot ever be a chunked seq as they are currently written.  There are just a whole lot of questions here.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13471/rt-chunkiteratorseq-does-not-produce-a-chunked-seq</guid>
<pubDate>Thu, 16 Nov 2023 15:05:15 +0000</pubDate>
</item>
<item>
<title>Seed support in java.util.Random</title>
<link>https://ask.clojure.org/index.php/13237/seed-support-in-java-util-random</link>
<description>&lt;p&gt;Is it possible to add additional arities for functions like &lt;code&gt;rand&lt;/code&gt;, &lt;code&gt;rand-int&lt;/code&gt;, &lt;code&gt;rand-nth&lt;/code&gt; etc. to support seeds passed to the Java methods? It could also be nice to create other functions for more secure variants than &lt;code&gt;java.util.Random&lt;/code&gt;, maybe &lt;code&gt;SecureRandom&lt;/code&gt;? I really don't know what is most widely used so that's just an idea.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13237/seed-support-in-java-util-random</guid>
<pubDate>Wed, 30 Aug 2023 17:01:05 +0000</pubDate>
</item>
<item>
<title>Request to find and eliminate virtual thread pinning</title>
<link>https://ask.clojure.org/index.php/12991/request-to-find-and-eliminate-virtual-thread-pinning</link>
<description>&lt;p&gt;Asking this here because I can't post to &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/CLJ-2771&quot;&gt;https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/CLJ-2771&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I run a startup and we ran headlong into this &lt;code&gt;synchronized&lt;/code&gt; block when using Java 19 virtual threads:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/jvm/clojure/lang/Delay.java#L35&quot;&gt;https://github.com/clojure/clojure/blob/4090f405466ea90bbaf3addbe41f0a6acb164dbb/src/jvm/clojure/lang/Delay.java#L35&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This took significant engineering effort and sanity to debug, as &lt;code&gt;-Djdk.tracePinnedThreads&lt;/code&gt; reported precisely nothing.&lt;/p&gt;
&lt;p&gt;As it stands, we're needing to reimplement a virtual-thread-friendly (non-&lt;code&gt;synchronized&lt;/code&gt;) &lt;code&gt;clojure.core/delay&lt;/code&gt;, and as many &lt;code&gt;clojure.core&lt;/code&gt; functions as we need to ensure virtual threads don't get pinned.&lt;/p&gt;
&lt;p&gt;As always, I'm amazed by the Clojure team's work! Just wanted to highlight the virtual-thread-unfriendliness of some of its API and get it prioritized if possible, since virtual threads are extremely useful.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12991/request-to-find-and-eliminate-virtual-thread-pinning</guid>
<pubDate>Thu, 01 Jun 2023 06:02:37 +0000</pubDate>
</item>
<item>
<title>Odd performance penalty on numeric benchmark alleviated by going to doubles...</title>
<link>https://ask.clojure.org/index.php/12536/performance-penalty-numeric-benchmark-alleviated-doubles</link>
<description>&lt;p&gt;I happened across the performance benchmark &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/niklas-heer/speed-comparison/blob/master/src/leibniz.clj&quot;&gt;here&lt;/a&gt; and I was curious why clojure was getting beaten by java.&lt;/p&gt;
&lt;p&gt;So I tossed it into the profiler (after modifying their version to use unchecked math - which didn't help) and nothing shows up. hmm. decompile and find that&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Decompiling class: leibniz$calc_pi_leibniz
import clojure.lang.*;

public final class leibniz$calc_pi_leibniz extends AFunction implements LD
{
    public static double invokeStatic(final long rounds) {
        final long end = 2L + rounds;
        long i = 2L;
        double x = 1.0;
        double pi = 1.0;
        while (i != end) {
            final double x2 = -x;
            final long n = i + 1L;
            final double n2 = x2;
            pi += Numbers.divide(x2, 2L * i - 1L);
            x = n2;
            i = n;
        }
        return Numbers.unchecked_multiply(4L, pi);
    }

    @Override
    public Object invoke(final Object o) {
        return invokeStatic(RT.uncheckedLongCast(o));
    }

    @Override
    public final double invokePrim(final long rounds) {
        return invokeStatic(rounds);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So looks like the double/long boundary is costing us at least a method lookup maybe in Numbers.divide?&lt;br&gt;
So I just coerce everything to double (even our index variable):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def rounds 100000000)

(defn calc-pi-leibniz2
  &quot;Eliminate mixing of long/double to avoid clojure.numbers invocations.&quot;
  ^double
  [^long rounds]
  (let [end (+ 2.0 rounds)]
    (loop [i 2.0 x 1.0 pi 1.0]
      (if (= i end)
        (* 4.0 pi)
        (let [x (- x)]
          (recur (inc i) x (+ pi (/ x (dec (* 2 i))))))))))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;leibniz=&amp;gt; (c/quick-bench (calc-pi-leibniz rounds))
Evaluation count : 6 in 6 samples of 1 calls.
             Execution time mean : 575.352216 ms
    Execution time std-deviation : 10.070268 ms
   Execution time lower quantile : 566.210399 ms ( 2.5%)
   Execution time upper quantile : 588.772187 ms (97.5%)
                   Overhead used : 1.884700 ns
nil
leibniz=&amp;gt; (c/quick-bench (calc-pi-leibniz2 rounds))
Evaluation count : 6 in 6 samples of 1 calls.
             Execution time mean : 158.509049 ms
    Execution time std-deviation : 759.113165 ╡s
   Execution time lower quantile : 157.234899 ms ( 2.5%)
   Execution time upper quantile : 159.205374 ms (97.5%)
                   Overhead used : 1.884700 ns
nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any ideas why the  &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/niklas-heer/speed-comparison/blob/master/src/leibniz.java&quot;&gt;java implementation&lt;/a&gt; not paying the same penalty for division? [both versions are implemented with unchecked-math at :warn-on-boxed].&lt;/p&gt;
&lt;p&gt;I also tried a variant with fastmath's primitive math operators and actually got slower.  So far nothing has beaten coercing the loop index &lt;code&gt;i&lt;/code&gt; into a double (which I would normally never do).&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12536/performance-penalty-numeric-benchmark-alleviated-doubles</guid>
<pubDate>Tue, 10 Jan 2023 17:51:55 +0000</pubDate>
</item>
<item>
<title>How to use local library from ~/.m2 directory</title>
<link>https://ask.clojure.org/index.php/12530/how-to-use-local-library-from-m2-directory</link>
<description>&lt;p&gt;Hello, I am unable to find out how to import and use a library from my local ~.m2 directory using leiningen. I have installed [apache pdfbox 2.0.27] (&lt;a rel=&quot;nofollow&quot; href=&quot;https://pdfbox.apache.org/&quot;&gt;https://pdfbox.apache.org/&lt;/a&gt;) using groupID 'deps' and artifactID 'pdfbox' and added it to my project.clj (until here everything seems to work fine as &lt;code&gt;lein install&lt;/code&gt; does not complain). Now I am trying to import the pdmodel.PDDocument class as instructed &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.tutorialspoint.com/pdfbox/pdfbox_loading_a_document.htm&quot;&gt;here&lt;/a&gt; by supplying the :import option to the ns function. However, it doesn't seem to work, and I am unable to find documentation that works for me.&lt;/p&gt;
&lt;p&gt;Should I import deps.pdfbox, or just pdfbox, and then for class import pdmodel, or pdmodel.PDDocument? Or, as this all does not seem to work, am I doing anything else wrong?&lt;/p&gt;
&lt;p&gt;Anyone here has any advice? Thank you!&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12530/how-to-use-local-library-from-m2-directory</guid>
<pubDate>Mon, 09 Jan 2023 20:42:16 +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>Java method overloaded</title>
<link>https://ask.clojure.org/index.php/12208/java-method-overloaded</link>
<description>&lt;p&gt;I’m a newbie to Clojure. I want to call a Java method which is overloaded in Java, one has no parameter and the other has one parameter. I want to call the method with no parameter, but Clojure calls the method with one parameter and raise an IllegalArgumentException.&lt;/p&gt;
&lt;p&gt;How can I call the Java method with no parameter from Clojure?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12208/java-method-overloaded</guid>
<pubDate>Fri, 16 Sep 2022 01:07:57 +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>Why does identical? treat let-bound ##NaN differently from direct reference to it?</title>
<link>https://ask.clojure.org/index.php/11963/identical-treat-bound-nan-differently-direct-reference</link>
<description>&lt;p&gt; Consider the following code snippets evaluated with Clojure 1.11.1:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; example 1
user=&amp;gt; (identical? Double/NaN Double/NaN)
false

;; example 2
user=&amp;gt; (let [x Double/NaN] (identical? x x))
false

;; example 3
user=&amp;gt; (identical? ##NaN ##NaN)
true

;; example 4
user=&amp;gt; (let [x ##NaN] (identical? x x))
false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why does example 3 return &lt;code&gt;true&lt;/code&gt; when all the other examples return &lt;code&gt;false&lt;/code&gt;? Is this the intended behavior?&lt;/p&gt;
&lt;p&gt;I assume this has something to do with with how Clojure sometimes uses unboxed math.&lt;/p&gt;
&lt;p&gt;In my mental model for Clojure, &lt;code&gt;identical?&lt;/code&gt; is basically &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/javase/specs/jls/se17/html/jls-15.html#jls-15.21&quot;&gt;Java's &lt;code&gt;==&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;##NaN&lt;/code&gt; is &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Double.html#NaN&quot;&gt;Java's &lt;code&gt;Double.NaN&lt;/code&gt;&lt;/a&gt;. In Java, &lt;code&gt;Double.NaN == Double.NaN&lt;/code&gt; evaluates to false. Thus I expected all the examples to return false. &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11963/identical-treat-bound-nan-differently-direct-reference</guid>
<pubDate>Tue, 14 Jun 2022 14:13:39 +0000</pubDate>
</item>
<item>
<title>Could realized? support Java futures?</title>
<link>https://ask.clojure.org/index.php/11913/could-realized-support-java-futures</link>
<description>&lt;p&gt;I'm running into a situation where I would need to mix CompletableFutures in with Clojure futures/delays/etc. Unfortunately, IPending is an interface, which can't be extended to Java core classes.&lt;/p&gt;
&lt;p&gt;For IDeref and IBlockingDeref, it's not a problem working with Java Futures, because the &lt;code&gt;deref&lt;/code&gt; fn supports them.&lt;/p&gt;
&lt;p&gt;Couldn't the same be done with the &lt;code&gt;realized?&lt;/code&gt; fn? Currently, it only works with IPending. It would be ideal if it matched the &lt;code&gt;deref&lt;/code&gt; behavior and called &lt;code&gt;.isDone()&lt;/code&gt; when given a java.util.concurrent.Future.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11913/could-realized-support-java-futures</guid>
<pubDate>Sat, 28 May 2022 07:16:15 +0000</pubDate>
</item>
<item>
<title>Why isn't there type inference for self-evident cases?</title>
<link>https://ask.clojure.org/index.php/11860/why-isnt-there-type-inference-for-self-evident-cases</link>
<description>&lt;p&gt;I often find myself addressing reflection warnings by placing annotations which type is completely obvious:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def ^String foo &quot;bar&quot;) ;; adding ^String fixes reflection warnings elsewhere
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;&quot;bar&quot;&lt;/code&gt; is a String, that is unmistakably known at compile-time, so it seems to me that I'm doing grunt work, and also creating something that might become outdated later.&lt;/p&gt;
&lt;p&gt;Has it been considered to add &quot;type inference&quot; for such straightforward cases?&lt;/p&gt;
&lt;p&gt;(&quot;type inference&quot; is probably an exaggerated term for this use case)&lt;/p&gt;
&lt;p&gt;...I can imagine at least one objection: &lt;code&gt;(def ^CharSequence foo &quot;bar&quot;)&lt;/code&gt; can also be accurate and useful. But a good default would be to infer the type of &lt;em&gt;x&lt;/em&gt; to be the &lt;em&gt;x&lt;/em&gt;'s class - if a user wanted to annotate &lt;em&gt;x&lt;/em&gt; as one of its ancestors (here: CharSequence, Object), he could override the inferred default by hand.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11860/why-isnt-there-type-inference-for-self-evident-cases</guid>
<pubDate>Thu, 05 May 2022 08:49:55 +0000</pubDate>
</item>
<item>
<title>Pesky loop bug resulting in 0xFFFFFFFF with BufferedReader (java interop)</title>
<link>https://ask.clojure.org/index.php/11415/pesky-loop-resulting-0xffffffff-with-bufferedreader-interop</link>
<description>&lt;p&gt;Hello --&lt;/p&gt;
&lt;p&gt;I'm learning Clojure and its Java interop stuff. I am trying to emulate this function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; public String readAllCharsOneByOne(BufferedReader bufferedReader) throws IOException {
    StringBuilder content = new StringBuilder();
       
    int value;
    while ((value = bufferedReader.read()) != -1) {
        content.append((char) value);
    }
       
    return content.toString();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far, I've been able to reason that the parts I need are:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def myfile &quot;/path/to/svenska_sample.txt&quot;)
(import java.io.BufferedReader)
(import java.io.FileReader)
(import java.lang.StringBuilder)
(import java.lang.Character)
 
(def a-FileReader (FileReader. myfile))
(def bufferedReader (BufferedReader. a-FileReader))
(def content (StringBuilder.))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which works&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDe&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen &quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen t&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen ty&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen typ&quot;]
user&amp;gt; (.append content (Character/toChars (.read bufferedReader)))
#object[java.lang.StringBuilder 0x490447d0 &quot;\nDen typi&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The file is a small text file UTF-8 encoded in Linux with the following content:&lt;/p&gt;
&lt;p&gt;❯ cat svenska_sample.txt&lt;/p&gt;
&lt;p&gt;Den typiska impulsiva olycksfågeln är en ung man som kraschar flera bilar, och ofta skryter lite med det, i varje fall när han är tillsammans med sina vänner._. För dem har otur i det närmaste blivit en livsstil, och de råkar konstant ut för olyckor, stora som små. Olycksfåglar kallar vi dem. Hur många det finns kan ingen med säkerhet säga, för det finns inga konkreta definitioner på denna grupp, och heller ingen given avgränsning av den. Att de finns, råder det emellertid ingen tvekan om, varken på sjukhusens akutmottagningar eller i försäkringsbranschen&lt;/p&gt;
&lt;p&gt;I wrote a function, with my brand new Clojure Java interop chops, that looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; COMPILES  - BUT CAN'T GET AROUND THE 0XFFFFFFF BUG
(defn pt%% [file]
   (let [afr (FileReader. file); instances of FileReader, BufferedReader, StringBuffer
         bfr (BufferedReader. afr)
         ct (StringBuilder.)
         val (.read bfr)
         this-list (list afr bfr ct)]
         ; (apply println this-list)
         (loop []
               (when (not (= val -1))
                 (.append ct (Character/toChars (.read bfr))))
               (recur))
                ; when finished...
         (.toString ct)))
     
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but it borks with the following error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (pt%% myfile)
Execution error (IllegalArgumentException) at java.lang.Character/toChars (Character.java:8572).
Not a valid Unicode code point: 0xFFFFFFFF
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What in the world could be causing this (NOTE: I am not a Java programmer)?&lt;br&gt;
Here is the hex dump of the file text file:&lt;/p&gt;
&lt;p&gt;❯ cat svenska_sample.hexdump&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;00000000: 0a44 656e 2074 7970 6973 6b61 2069 6d70  .Den typiska imp
00000010: 756c 7369 7661 206f 6c79 636b 7366 c3a5  ulsiva olycksf..
00000020: 6765 6c6e 20c3 a472 2065 6e20 756e 6720  geln ..r en ung
00000030: 6d61 6e20 736f 6d20 6b72 6173 6368 6172  man som kraschar
00000040: 2066 6c65 7261 2062 696c 6172 2c20 6f63   flera bilar, oc
00000050: 6820 6f66 7461 2073 6b72 7974 6572 206c  h ofta skryter l
00000060: 6974 6520 6d65 6420 6465 742c 2069 2076  ite med det, i v
00000070: 6172 6a65 2066 616c 6c20 6ec3 a472 2068  arje fall n..r h
00000080: 616e 20c3 a472 2074 696c 6c73 616d 6d61  an ..r tillsamma
00000090: 6e73 206d 6564 2073 696e 6120 76c3 a46e  ns med sina v..n
000000a0: 6e65 722e 5f2e 2046 c3b6 7220 6465 6d20  ner._. F..r dem
000000b0: 6861 7220 6f74 7572 2069 2064 6574 206e  har otur i det n
000000c0: c3a4 726d 6173 7465 2062 6c69 7669 7420  ..rmaste blivit
000000d0: 656e 206c 6976 7373 7469 6c2c 206f 6368  en livsstil, och
000000e0: 2064 6520 72c3 a56b 6172 206b 6f6e 7374   de r..kar konst
000000f0: 616e 7420 7574 2066 c3b6 7220 6f6c 7963  ant ut f..r olyc
00000100: 6b6f 722c 2073 746f 7261 2073 6f6d 2073  kor, stora som s
00000110: 6dc3 a52e 204f 6c79 636b 7366 c3a5 676c  m... Olycksf..gl
00000120: 6172 206b 616c 6c61 7220 7669 2064 656d  ar kallar vi dem
00000130: 2e20 4875 7220 6dc3 a56e 6761 2064 6574  . Hur m..nga det
00000140: 2066 696e 6e73 206b 616e 2069 6e67 656e   finns kan ingen
00000150: 206d 6564 2073 c3a4 6b65 7268 6574 2073   med s..kerhet s
00000160: c3a4 6761 2c20 66c3 b672 2064 6574 2066  ..ga, f..r det f
00000170: 696e 6e73 2069 6e67 6120 6b6f 6e6b 7265  inns inga konkre
00000180: 7461 2064 6566 696e 6974 696f 6e65 7220  ta definitioner
00000190: 70c3 a520 6465 6e6e 6120 6772 7570 702c  p.. denna grupp,
000001a0: 206f 6368 2068 656c 6c65 7220 696e 6765   och heller inge
000001b0: 6e20 6769 7665 6e20 6176 6772 c3a4 6e73  n given avgr..ns
000001c0: 6e69 6e67 2061 7620 6465 6e2e 2041 7474  ning av den. Att
000001d0: 2064 6520 6669 6e6e 732c 2072 c3a5 6465   de finns, r..de
000001e0: 7220 6465 7420 656d 656c 6c65 7274 6964  r det emellertid
000001f0: 2069 6e67 656e 2074 7665 6b61 6e20 6f6d   ingen tvekan om
00000200: 2c20 7661 726b 656e 2070 c3a5 2073 6a75  , varken p.. sju
00000210: 6b68 7573 656e 7320 616b 7574 6d6f 7474  khusens akutmott
00000220: 6167 6e69 6e67 6172 2065 6c6c 6572 2069  agningar eller i
00000230: 2066 c3b6 7273 c3a4 6b72 696e 6773 6272   f..rs..kringsbr
00000240: 616e 7363 6865 6e0a                      anschen.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then changed the code (see below), because of some suggestions that the problem might be my use of recur.&lt;/p&gt;
&lt;p&gt;And now it complains that a previous form that was working '(.append etc..') doesn't and the same error remains. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (pt5 myfile)

Execution error (IllegalArgumentException) at java.lang.Character/toChars (Character.java:8572).
Not a valid Unicode code point: 0xFFFFFFFF

(defn pt5 [file]

   (let [afr (FileReader. file); instances of FileReader, BufferedReader, StringBuffer
         bfr (BufferedReader. afr)
         ct (StringBuilder.)
         this-list (list afr bfr ct)]
         ; (apply println this-list)
         (loop [val (.read bfr)]
               (when (not (= val -1))
                 (.append ct (Character/toChars (.read bfr))))
               (recur val))
                ; when finished...
                (.toString ct)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Harder then it seemed at first sight...&lt;br&gt;
Any help is greatly appreciated.`&lt;br&gt;
-- Hank&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11415/pesky-loop-resulting-0xffffffff-with-bufferedreader-interop</guid>
<pubDate>Sun, 26 Dec 2021 13:20:55 +0000</pubDate>
</item>
<item>
<title>The clojure `rand-int` method seems to be 4 times slower than its java counterpart `java.util.Random.nextInt()`</title>
<link>https://ask.clojure.org/index.php/10669/clojure-method-seems-times-slower-counterpart-random-nextint</link>
<description>&lt;p&gt;Check the below &lt;a rel=&quot;nofollow&quot; href=&quot;https://gist.github.com/a30660391c68255e65ff60970e706c22&quot;&gt;gist&lt;/a&gt; to see detailed results.&lt;/p&gt;
&lt;p&gt;Note that using interop is ok for me, &lt;br&gt;
I am in an operations research use case where time consumption of random value is important.&lt;/p&gt;
&lt;p&gt;But I wonder why clojure should not propose a better version of rand-int.&lt;/p&gt;
&lt;p&gt;I suspect (but I will check if needed) that the &lt;code&gt;nextInt&lt;/code&gt; version may be more uniform (statistically closer from the theory).&lt;/p&gt;
&lt;p&gt;PS: Duplicate from a question in slack, channel clojure.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10669/clojure-method-seems-times-slower-counterpart-random-nextint</guid>
<pubDate>Fri, 04 Jun 2021 09:12:42 +0000</pubDate>
</item>
<item>
<title>Unable to run Clara Rules from Java</title>
<link>https://ask.clojure.org/index.php/10662/unable-to-run-clara-rules-from-java</link>
<description>&lt;p&gt;Im beginning to learn Clara Rules and wanted to execute them from Java. I'm getting an error when trying to run the code. &lt;code&gt;ExceptionInInitializerError: Syntax error compiling at (example/shopping.clj:2:3). clara.rules.accumulators&lt;/code&gt;. I'm attaching the project source for your reference. Could you please help. Please install Maven. Go to your project root directory and to compile the project execute &lt;code&gt;mvn -q compile&lt;/code&gt; To run the code &lt;code&gt;mvn -q exec:java -Dexec.mainClass=example.ClaraExampleMain&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://drive.google.com/drive/folders/1axsfs9mP1Uv2Q3qyZPHWMeZdJdmRwox5?usp=sharing&quot;&gt;SourceCode to the project&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10662/unable-to-run-clara-rules-from-java</guid>
<pubDate>Sat, 29 May 2021 12:17:53 +0000</pubDate>
</item>
<item>
<title>into-array should not need type hints</title>
<link>https://ask.clojure.org/index.php/10609/into-array-should-not-need-type-hints</link>
<description>&lt;p&gt;Currently into-array's return value needs type hinting in addition to having to specify the target class in the first place. Type hinting array types isn't exactly trivial either (with the weird and extremely verbose ^&quot;[Lorg.clojure.MyClass;&quot; syntax).&lt;/p&gt;
&lt;p&gt;It would be really nice if the compiler could deal with that for the user.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10609/into-array-should-not-need-type-hints</guid>
<pubDate>Sat, 15 May 2021 16:49:15 +0000</pubDate>
</item>
<item>
<title>Type hints getting ignored, reverting to java.lang.Object</title>
<link>https://ask.clojure.org/index.php/10555/type-hints-getting-ignored-reverting-to-java-lang-object</link>
<description>&lt;pre&gt;&lt;code&gt;  (deftype l [^java.util.List x])
  (use '[clojure.reflect :as r])
  (:members (r/reflect (l. `())))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Despite the type-hints of &lt;code&gt;java.util.List&lt;/code&gt;, on reflection x seems to always be an Object&lt;/p&gt;
&lt;p&gt;Have been specifically trying to get an optaplanner example working in 100% clojure &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/joinr/optaplanner-clj/tree/163d326a6433b88ca9811e33d30758ceff42b91f&quot;&gt;https://github.com/joinr/optaplanner-clj/tree/163d326a6433b88ca9811e33d30758ceff42b91f&lt;/a&gt; . The code is evaluating but this error keeps occurring on running &lt;code&gt;(solve (-&amp;gt;problem))&lt;/code&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;ol&gt;
&lt;li&gt;Unhandled java.lang.IllegalStateException    The solutionClass (class optaplanner_clj.data.TimeTable) has a &lt;br&gt;
PlanningEntityCollectionProperty annotated member (public final &lt;br&gt;
java.lang.Object optaplanner_clj.data.TimeTable.lessonList) that does&lt;br&gt;
not    return a Collection or an array.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10555/type-hints-getting-ignored-reverting-to-java-lang-object</guid>
<pubDate>Sun, 02 May 2021 01:56:00 +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>Problems loading ffmpeg library with jna</title>
<link>https://ask.clojure.org/index.php/10128/problems-loading-ffmpeg-library-with-jna</link>
<description>&lt;p&gt;Hi, I have a problem trying to call a C library using JNA (on a windows platform, using vscode).&lt;/p&gt;
&lt;p&gt;I grabbed a copy of the ffmpeg shared libraries from: &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gyan.dev/ffmpeg/builds/&quot;&gt;https://www.gyan.dev/ffmpeg/builds/&lt;/a&gt;&lt;br&gt;
specifically: &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z&quot;&gt;https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I took the contents of the bin sub-directory and put it in the 'lib' directory of my clojure project. I also added this directory to my path and could happily call the ffmpeg app.&lt;/p&gt;
&lt;p&gt;Here is the contents of my deps.edn:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:deps
 {net.java.dev.jna/jna   {:mvn/version &quot;5.6.0&quot;}}
 :paths [&quot;src&quot; &quot;lib&quot;]
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And here is the code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (ns jnatest)

(import (com.sun.jna  Native Pointer))

(gen-interface
 :name jna.lib_avformat
 :extends [com.sun.jna.Library]
 :methods [[avformat_alloc_context [] Pointer]])

(def avformat
  (Native/loadLibrary &quot;avformat-58&quot; jna.lib_avformat))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On the the call to Native/loadLibrary I get the error:&lt;/p&gt;
&lt;p&gt;; Execution error (UnsatisfiedLinkError) at com.sun.jna.Native/open (Native.java:-2).&lt;br&gt;
; %1 is not a valid Win32 application.&lt;/p&gt;
&lt;p&gt;I initially started with the techascent jna implementation, &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojars.org/techascent/tech.jna&quot;&gt;https://clojars.org/techascent/tech.jna&lt;/a&gt;, and had similiar issues, so I went back to basics.&lt;/p&gt;
&lt;p&gt;I'm guessing it's something wrong with the libraries, but before I start recompiling all the ffmpeg libraries I thought I'd ask if there might be something simple to try.&lt;/p&gt;
&lt;p&gt;Any hints appreciated.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10128/problems-loading-ffmpeg-library-with-jna</guid>
<pubDate>Sat, 30 Jan 2021 18:03:48 +0000</pubDate>
</item>
<item>
<title>Fails to load gen-classed class with pf4j from uberjar</title>
<link>https://ask.clojure.org/index.php/10093/fails-to-load-gen-classed-class-with-pf4j-from-uberjar</link>
<description>&lt;p&gt;The problem here might be more related to the pf4j default classloader but still:&lt;/p&gt;
&lt;p&gt;I have a clojure plugin generating a class &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(gen-class
 :name myplugin.SomeExtension
 :implements [plugin.SomeExtensionPoint]
 :prefix &quot;-&quot;
 :impl-ns my-plugin.some-extension)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The plugin jar  is loaded in my clojure application using pf4j. When it is compiled with &lt;code&gt;lein jar&lt;/code&gt; the class loads (but then I naturally have to put any plugin dependencies in the apps &lt;code&gt;project.clj&lt;/code&gt;). When compiled with &lt;code&gt;lein uberjar&lt;/code&gt; it fails with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; Execution error (IllegalStateException) at myplugin.SomeExtension/&amp;lt;clinit&amp;gt; (REPL:-1).
; Attempting to call unbound fn: #'clojure.core/refer
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with top of call stack&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;jdk.internal.reflect.NativeConstructorAccessorImpl/newInstance0 (NativeConstructorAccessorImpl.java:-2)
jdk.internal.reflect.NativeConstructorAccessorImpl/newInstance (NativeConstructorAccessorImpl.java:62)
jdk.internal.reflect.DelegatingConstructorAccessorImpl/newInstance (DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor/newInstance (Constructor.java:490)
java.lang.Class/newInstance (Class.java:584)
org.pf4j.DefaultExtensionFactory/create (DefaultExtensionFactory.java:38)
org.pf4j.ExtensionWrapper/getExtension (ExtensionWrapper.java:37)
org.pf4j.AbstractPluginManager/getExtensions (AbstractPluginManager.java:971)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I've struggled a bit but I am unsure about exactly what happens here and how to solve it?&lt;br&gt;
Any ideas are most welcome!&lt;/p&gt;
&lt;p&gt;(and the uberjar profile uses &lt;code&gt;{:aot :all :omit-source true}&lt;/code&gt;)&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10093/fails-to-load-gen-classed-class-with-pf4j-from-uberjar</guid>
<pubDate>Tue, 26 Jan 2021 16:23:57 +0000</pubDate>
</item>
<item>
<title>How to invoke native C-functions in Clojure via JNR-FFI?</title>
<link>https://ask.clojure.org/index.php/9915/how-to-invoke-native-c-functions-in-clojure-via-jnr-ffi</link>
<description>&lt;p&gt;Hi Everyone,&lt;/p&gt;
&lt;p&gt;I want to call native functions in a C-Library from Clojure via &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/jnr/jnr-ffi&quot;&gt;JNR-FFI&lt;/a&gt; without having to write Java code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defproject mypkg
	:dependencies [[org.clojure/clojure &quot;1.10.1&quot;]
				   [com.github.jnr/jnr-ffi &quot;2.2.0&quot;]])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Based on the jnr-ffi examples &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java&quot;&gt;here&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader&quot;&gt;here&lt;/a&gt; a Java wrapper might look like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package blahblah;

public class BlahNative {
	private static int[] intDummy;
	private static double[] doubleDummy;

	public BlahNative() {
	}

	public static native void native_a(char var0, char var1, int var2, int var3, int var4, double[] var7, int var8, int var9);

	public static native void native_b(char var0, char var1, int var2, int var3, int var4, double[] var7, int var8, int var9);

	static {
		lib = LibraryLoader
            .create(LibSodium.class)
            .search(&quot;/usr/local/lib&quot;)
            .search(&quot;/opt/local/lib&quot;)
            .search(&quot;/usr/lib&quot;)
            .search(&quot;/lib&quot;)
            .load(LIBRARY_NAME);
        initializeLibrary(lib);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I presume my Clojure namespace should use the &lt;a rel=&quot;nofollow&quot; href=&quot;http://clojure-doc.org/articles/language/interop.html&quot;&gt;gen-class&lt;/a&gt; feature for implementing Java classes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns mypkg.native
	(:import [jnr.ffi LibraryLoader])
	(:import [jnr.ffi.annotations IgnoreError])
	(:import [jnr.ffi.provider FFIProvider])
    (:gen-class))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;How do I write a &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.baeldung.com/java-native&quot;&gt;native&lt;/a&gt; method in Clojure? In other words, do I even need to specify the method type (as &lt;code&gt;native&lt;/code&gt;) when using Clojure's Java interop features?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After loading the native library I do not know how to access the C-functions in the library. How do I do it?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To avoid reloading the library for every Clojure wrapper function of each C-functions, can I write a method like&lt;/p&gt;
&lt;p&gt; &lt;code&gt;(defn lib (. LibraryLoader load LIBRARY_NAME))&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;and then access the native functions in it?&lt;/p&gt;
&lt;p&gt;I am neither a C nor a Java expert so any guidance will be much appreciated.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9915/how-to-invoke-native-c-functions-in-clojure-via-jnr-ffi</guid>
<pubDate>Fri, 04 Dec 2020 13:57:56 +0000</pubDate>
</item>
<item>
<title>Could not initialize class javafx.stage.Screen</title>
<link>https://ask.clojure.org/index.php/9632/could-not-initialize-class-javafx-stage-screen</link>
<description>&lt;p&gt;I've been trying to use javafx.stage.Screen to capture my screen dimensions. &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Screen.html&quot;&gt;following java documentations&lt;/a&gt;&lt;br&gt;
here is what I wrote&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(import javafx.stage.Screen)
(Screen/getPrimary)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I get the following error&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Execution error (NoClassDefFoundError) at user/eval194 (REPL:1).&lt;br&gt;
Could not initialize class javafx.stage.Screen&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I tried using the fully qualified named and using the dot special form but I get the same error. in the docs the class screen has no constructor so I don't think I need make new instance.&lt;br&gt;
java version: 1.8.0_261&lt;br&gt;
repl : clj  1.10.0.442&lt;br&gt;
command line: powershell  5.1.17763.1432&lt;/p&gt;
&lt;p&gt;any idea why this happens?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9632/could-not-initialize-class-javafx-stage-screen</guid>
<pubDate>Tue, 22 Sep 2020 23:24:10 +0000</pubDate>
</item>
<item>
<title>Why does bit-shift-left rotate bits instead of discarding bits?</title>
<link>https://ask.clojure.org/index.php/9518/why-does-bit-shift-left-rotate-bits-instead-discarding-bits</link>
<description>&lt;p&gt;&lt;code&gt;(bit-shift-left 0xfffffff0 4)&lt;/code&gt; returns &lt;code&gt;0xffffff0f&lt;/code&gt;, while I expect it to be &lt;code&gt;0xffffff00&lt;/code&gt;. Similarly, &lt;code&gt;(bit-shift-left 0xfffffff0 8)&lt;/code&gt; returns &lt;code&gt;0xfffff0ff&lt;/code&gt;, etc.&lt;/p&gt;
&lt;p&gt; I checked the implementation, and &lt;code&gt;bit-shift-left&lt;/code&gt; casts all its arguments to &lt;code&gt;Long&lt;/code&gt;, then invokes Java's &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator, which should discard higher bits instead of rotate them.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9518/why-does-bit-shift-left-rotate-bits-instead-discarding-bits</guid>
<pubDate>Mon, 03 Aug 2020 05:35:41 +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>defrecord could type hint the record constructor functions</title>
<link>https://ask.clojure.org/index.php/9168/defrecord-could-type-hint-the-record-constructor-functions</link>
<description>&lt;p&gt;Here's some code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(set! *warn-on-reflection* true)
(defrecord Foo [bar])
(.-bar (-&amp;gt;Foo &quot;bar&quot;))

;;&amp;gt; Reflection warning, NO_SOURCE_PATH:1:1 - reference to field bar can't be resolved.
;;=&amp;gt; &quot;bar&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As we can see, the generated &lt;code&gt;-&amp;gt;Foo&lt;/code&gt; function to construct record of type &lt;code&gt;Foo&lt;/code&gt; is not type hinted, and thus Clojure will use reflection when doing interop calls over it.&lt;/p&gt;
&lt;p&gt;It would be nice if Clojure would generate a type hinted constructor instead.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9168/defrecord-could-type-hint-the-record-constructor-functions</guid>
<pubDate>Fri, 20 Mar 2020 00:17:49 +0000</pubDate>
</item>
<item>
<title>Infer Var type hint in a def from the return type hint of the function call that initializes it</title>
<link>https://ask.clojure.org/index.php/9167/infer-hint-from-return-type-hint-function-call-initializes</link>
<description>&lt;p&gt;Here's an example code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(set! *warn-on-reflection* true)
(defn hello ^String []
  &quot;hello&quot;)
(def a (hello))
(.replace a \e \a)

;;&amp;gt; Reflection warning, NO_SOURCE_PATH:1:1 - call to method replace can't be resolved (target class is unknown).
;;=&amp;gt; &quot;hallo&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As we can see, Clojure doesn't seem to be able to infer the type of the Var &lt;code&gt;a&lt;/code&gt;, even though the function &lt;code&gt;(hello)&lt;/code&gt; had its return type hinted.&lt;/p&gt;
&lt;p&gt;It would be great if Clojure could infer this. Otherwise, as of now, the user must provide an explicit type hint for it.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9167/infer-hint-from-return-type-hint-function-call-initializes</guid>
<pubDate>Fri, 20 Mar 2020 00:13:39 +0000</pubDate>
</item>
</channel>
</rss>