<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions and answers in Java Interop</title>
<link>https://ask.clojure.org/index.php/qa/clojure/java-interop</link>
<description></description>
<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>Answered: 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?show=14890#a14890</link>
<description>&lt;p&gt;Created jira and patch at &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2936&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2936&lt;/a&gt;&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?show=14890#a14890</guid>
<pubDate>Tue, 13 Jan 2026 19:06:31 +0000</pubDate>
</item>
<item>
<title>Answered: Could we get deref support on ScopedValue?</title>
<link>https://ask.clojure.org/index.php/14771/could-we-get-deref-support-on-scopedvalue?show=14773#a14773</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2926&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2926&lt;/a&gt;&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?show=14773#a14773</guid>
<pubDate>Tue, 25 Nov 2025 20:00:22 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=14769#a14769</link>
<description>&lt;p&gt;Probably tough to make it a protocol now, especially with backward compiled compatibility.&lt;/p&gt;
&lt;p&gt;It would be best to vote on the &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional&quot;&gt;question for Optional&lt;/a&gt; to voice your opinion there - we look at higher voted things with more urgency.&lt;/p&gt;
&lt;p&gt;ScopedValue is only available non-preview in 25, so pretty new still. would probably be best to file an Ask question specifically about that so it can gather votes.&lt;/p&gt;
&lt;p&gt;LazyConstant is not a thing yet, so will be a long while probably.&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?show=14769#a14769</guid>
<pubDate>Mon, 24 Nov 2025 20:55:02 +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>Answered: Refection warning even with type hinting</title>
<link>https://ask.clojure.org/index.php/14622/refection-warning-even-with-type-hinting?show=14625#a14625</link>
<description>&lt;p&gt;You could type hint the &lt;strong&gt;target&lt;/strong&gt; (which is what the warning is about, not the argument types):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (type *err*)
java.io.PrintWriter
user=&amp;gt; (.println ^java.io.PrintWriter *err* &quot;foo&quot;)
foo
nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I suspect this is because &lt;code&gt;*err*&lt;/code&gt; is a dynamically bound var so the compiler doesn't know its type, even tho' the bound &lt;em&gt;value&lt;/em&gt; is &lt;code&gt;java.io.PrintWriter&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You could also use the new-in-1.12 qualified method access, to avoid the warning:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (set! *warn-on-reflection* true)
true
user=&amp;gt; (.println *err* &quot;foo&quot;)
Reflection warning, NO_SOURCE_PATH:1:1 - call to method println can't be resolved (target class is unknown).
foo
nil
user=&amp;gt; (import 'java.io.PrintWriter)
java.io.PrintWriter
user=&amp;gt; (PrintWriter/.println *err* &quot;foo&quot;)
foo
nil
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14622/refection-warning-even-with-type-hinting?show=14625#a14625</guid>
<pubDate>Fri, 11 Jul 2025 15:13:01 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=14614#a14614</link>
<description>&lt;p&gt;This is a known issue with reflection (it's actually not entirely deterministic - both methods match and either may get chosen depending on the JVM and other factors). &lt;/p&gt;
&lt;p&gt;The important takeaway is that you are leaving the choice to reflection rather than making it explicit. If you use &lt;code&gt;(set! *warn-on-reflection* true)&lt;/code&gt; you should see a warning here.&lt;/p&gt;
&lt;p&gt;You can use either a type hint &lt;code&gt;(AIMesh/create ^long pointer)&lt;/code&gt; or an explicit coercion &lt;code&gt;(AIMesh/create (long pointer))&lt;/code&gt; or param-tags metadata &lt;code&gt;(^[long] AIMesh/create pointer)&lt;/code&gt;  to remove the ambiguity. You should see the warning go away if it's working.&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?show=14614#a14614</guid>
<pubDate>Sat, 05 Jul 2025 22:28:50 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=14597#a14597</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2914&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2914&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14596/qualified-instance-compile-nullpointerexception-missing?show=14597#a14597</guid>
<pubDate>Mon, 30 Jun 2025 13:46:55 +0000</pubDate>
</item>
<item>
<title>Answered: Default Imports Don't Include Clojure Internals</title>
<link>https://ask.clojure.org/index.php/14586/default-imports-dont-include-clojure-internals?show=14587#a14587</link>
<description>&lt;p&gt;Well, where do you stop?  Only Rich could tell you but I assume he was experimenting and decided that &quot;where to stop&quot; was with java.lang.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14586/default-imports-dont-include-clojure-internals?show=14587#a14587</guid>
<pubDate>Tue, 24 Jun 2025 14:20:25 +0000</pubDate>
</item>
<item>
<title>Answered: Idiomatic way to use java.util.Optional</title>
<link>https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional?show=14502#a14502</link>
<description>&lt;p&gt;Logged enhancement at &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2905&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2905&lt;/a&gt;&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?show=14502#a14502</guid>
<pubDate>Mon, 07 Apr 2025 14:31:43 +0000</pubDate>
</item>
<item>
<title>Answered: Using java.data</title>
<link>https://ask.clojure.org/index.php/14490/using-java-data?show=14491#a14491</link>
<description>&lt;p&gt;Since you're a beginner I'll mentioned right off the bat the &lt;code&gt;#beginners&lt;/code&gt; channels on both Clojurians Zulip and Clojurians Slack. They allow for a much better interactivity with the community when you need help with something.&lt;/p&gt;
&lt;p&gt;Your description lacks important details. Ideally, there should be an MRE (Minimal Reproducible Example) which shows what you want to achieve, what you currently have, and what doesn't work.&lt;br&gt;
Since I don't know what your Java classes look like, what your modification to &lt;code&gt;clojure.java.data&lt;/code&gt; is exactly, how you use the resulting data, I can't really help here. So at the very least, just those things should be shown.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;clojure.java.data&lt;/code&gt; has both &lt;code&gt;from-java&lt;/code&gt; and &lt;code&gt;from-java-deep&lt;/code&gt;. The former recurses only for &lt;code&gt;Iterable&lt;/code&gt;, but even there it uses &lt;code&gt;for&lt;/code&gt; so it &quot;escapes&quot; the recursion and should not lead to a stack overflow. &lt;code&gt;from-java-deep&lt;/code&gt; does use a proper recursion, so it's bound to hit SO on specific data types that are nested deeply enough.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14490/using-java-data?show=14491#a14491</guid>
<pubDate>Wed, 02 Apr 2025 16:37:21 +0000</pubDate>
</item>
<item>
<title>Answered: SourceDataLine method not found</title>
<link>https://ask.clojure.org/index.php/14351/sourcedataline-method-not-found?show=14352#a14352</link>
<description>&lt;p&gt;I suspect the latter case is using reflection (because you've lost the interface return type of getSourceDataLine), and you are thus searching the concrete class for the method, which may not be accessible due to module visibility.&lt;/p&gt;
&lt;p&gt;If so, you could try:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn getline ^javax.sound.sampled.SourceDataLine []
  (AudioSystem/getSourceDataLine fmt))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That flows the interface type into play2 where it should be able to make the same calculation as in play1. &lt;/p&gt;
&lt;p&gt;BTW, you might find &lt;code&gt;doto&lt;/code&gt; could simplify that code in the play methods.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14351/sourcedataline-method-not-found?show=14352#a14352</guid>
<pubDate>Wed, 22 Jan 2025 21:51:06 +0000</pubDate>
</item>
<item>
<title>Answered: Java interop issue</title>
<link>https://ask.clojure.org/index.php/14240/java-interop-issue?show=14241#a14241</link>
<description>&lt;p&gt;Can you do &lt;code&gt;(pst *e)&lt;/code&gt; and provide that too?  It's complaining about ApplicationCommon class which does not seem accessible from Clojure's classloader. That class doesn't show up in your code so I'm not sure how/why it's needed but might be something classloader related.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14240/java-interop-issue?show=14241#a14241</guid>
<pubDate>Tue, 12 Nov 2024 22:12:25 +0000</pubDate>
</item>
<item>
<title>Answered: Using integer parameters in deftype annotations</title>
<link>https://ask.clojure.org/index.php/13998/using-integer-parameters-in-deftype-annotations?show=14001#a14001</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2868&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2868&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13998/using-integer-parameters-in-deftype-annotations?show=14001#a14001</guid>
<pubDate>Mon, 01 Jul 2024 13:52:52 +0000</pubDate>
</item>
<item>
<title>Answered: Wrong implementation of IBlockingDeref for clojure.java.process/start</title>
<link>https://ask.clojure.org/index.php/13990/wrong-implementation-iblockingderef-clojure-process-start?show=13992#a13992</link>
<description>&lt;p&gt;Thanks! Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2865&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2865&lt;/a&gt; - we will get that fixed before 1.12 release.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13990/wrong-implementation-iblockingderef-clojure-process-start?show=13992#a13992</guid>
<pubDate>Fri, 28 Jun 2024 13:47:27 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13888#a13888</link>
<description>&lt;p&gt;the last time I recall some discussion about this, I think rhickey rejected it because vars are mutable and type hints effect compilation, so if if you type hint a var as some type X later code will be compiled to depend on it, and won't be recompiled if you change the hinted type (which would be more likely to happen if the hint was automatic). so hints on vars are opt in not opt out.&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?show=13888#a13888</guid>
<pubDate>Fri, 17 May 2024 22:25:38 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13795#a13795</link>
<description>&lt;p&gt;Given the Java code, the &lt;code&gt;.build()&lt;/code&gt; method on the third line must also return an instance of &lt;code&gt;Consumer&lt;/code&gt;. So there's no need to reify anything, you should be able to use this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [consumer (-&amp;gt; (S3Configuration/builder) (.pathStyleAccessEnabled true) (.build))]
  (-&amp;gt; (S3Client/builder) (.seviceConfiguration consumer) (.build)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This pattern, where you create a builder, call a bunch of configuration methods on it, and then call &lt;code&gt;.build&lt;/code&gt; to get the final object that you actually need, is called a... &quot;builder&quot;. :) In the OOP world, it's quite helpful when you want to ensure encapsulation and that there are no partially built objects. It can also help in cases where you need to have multiple different builder using the same interface that behave differently. Or in cases where you have to separate creation of an object across different contexts.&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?show=13795#a13795</guid>
<pubDate>Tue, 26 Mar 2024 11:36:14 +0000</pubDate>
</item>
<item>
<title>Answered: Why can't I type hint these floats?</title>
<link>https://ask.clojure.org/index.php/13743/why-cant-i-type-hint-these-floats?show=13744#a13744</link>
<description>&lt;p&gt;Copying my answer from SO below.&lt;/p&gt;
&lt;p&gt;You can't. The error is quite clear. Even this fails:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (defn f [^float x])
Syntax error (IllegalArgumentException) compiling fn* at (REPL:1:1).
Only long and double primitives are supported
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can still use unboxed doubles. If that doesn't work for you, it might be better to implement this particular part in Java.&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?show=13744#a13744</guid>
<pubDate>Thu, 15 Feb 2024 19:06:34 +0000</pubDate>
</item>
<item>
<title>Answered: `resolve` should support array class symbols?</title>
<link>https://ask.clojure.org/index.php/13674/resolve-should-support-array-class-symbols?show=13675#a13675</link>
<description>&lt;p&gt;I'm not sure that resolve should work for this as it's really about looking things up in the namespace mappings. We'll talk about it though, thanks.&lt;/p&gt;
&lt;p&gt;This was logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2832&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2832&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13674/resolve-should-support-array-class-symbols?show=13675#a13675</guid>
<pubDate>Fri, 09 Feb 2024 02:52:55 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13576#a13576</link>
<description>&lt;p&gt;Created &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2821&quot;&gt;CLJ-2821&lt;/a&gt; to track this issue.&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?show=13576#a13576</guid>
<pubDate>Tue, 19 Dec 2023 01:38:11 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13502#a13502</link>
<description>&lt;p&gt;This happens because when the compiler converts a VarExpr invocation into an invokePrim expression, it loses the type hint from the arglist. I already have a patch for this if this gets converted into a JIRA ticket.&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?show=13502#a13502</guid>
<pubDate>Fri, 01 Dec 2023 19:33:25 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13492#a13492</link>
<description>&lt;p&gt;We ported to strcutrued logging with Markers, as wrote here: &lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/a/60101309/8162407&quot;&gt;https://stackoverflow.com/a/60101309/8162407&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;with a thin wrapper on clojure.tools.logging. really happy with it. Upvoting.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13491/add-support-for-context-logging-in-tools-logging?show=13492#a13492</guid>
<pubDate>Sun, 26 Nov 2023 17:04:35 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=13386#a13386</link>
<description>&lt;p&gt;Clojure 1.12.0-alpha5 is now available and modifies lazy-seq and delay to use locks instead of synchronized.&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?show=13386#a13386</guid>
<pubDate>Sat, 21 Oct 2023 19:41:59 +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>Answered: 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?show=12537#a12537</link>
<description>&lt;p&gt;I won't have time to take a look at this for a while, but it is pretty easy to fall into boxing at the loop/recur boundary which will cause substantial slowdowns, but it's easiest to tell for sure by looking at the bytecode. &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12536/performance-penalty-numeric-benchmark-alleviated-doubles?show=12537#a12537</guid>
<pubDate>Tue, 10 Jan 2023 18:46:08 +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>Answered: Cannot resolve public generic method from package-private base class</title>
<link>https://ask.clojure.org/index.php/4255/cannot-resolve-public-generic-method-package-private-class?show=12483#a12483</link>
<description>&lt;p&gt;Here is another example of code that works for Java but fails on Clojure. The example class comes from the &lt;code&gt;[org.opensearch.client/opensearch-java &quot;2.1.0&quot;]&lt;/code&gt; library.&lt;/p&gt;
&lt;p&gt;This Java code works without problems:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package example;

import org.opensearch.client.opensearch.core.bulk.IndexOperation;

import java.io.IOException;
import java.util.Map;

public class Example {
    public static void main(String[] args) throws IOException {
        new IndexOperation.Builder&amp;lt;Map&amp;lt;?, ?&amp;gt;&amp;gt;()
                .index(&quot;test-index&quot;)
                .id(&quot;test-id&quot;)
                .document(Map.of(&quot;test-document&quot;, 123))
                .build();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But the Clojure version cannot be written using Java interop. The workaround is to manually use reflection to call those methods:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns example
  (:import (org.opensearch.client.opensearch.core.bulk IndexOperation$Builder)))

(defn bug []
  (-&amp;gt; (IndexOperation$Builder.)
      (.index &quot;test-index&quot;)
      (.id &quot;test-id&quot;)
      (.document {&quot;test-document&quot; 123})
      (.build)))

(defn workaround []
  (let [bulk-builder-index (-&amp;gt; (Class/forName &quot;org.opensearch.client.opensearch.core.bulk.BulkOperationBase$AbstractBuilder&quot;)
                               (.getDeclaredMethod &quot;index&quot; (into-array Class [String])))
        bulk-builder-id (-&amp;gt; (Class/forName &quot;org.opensearch.client.opensearch.core.bulk.BulkOperationBase$AbstractBuilder&quot;)
                            (.getDeclaredMethod &quot;id&quot; (into-array Class [String])))]
    (-&amp;gt; (IndexOperation$Builder.)
        ^IndexOperation$Builder ((fn [builder index]
                                   (.invoke bulk-builder-index builder (into-array Object [index])))
                                 &quot;test-index&quot;)
        ^IndexOperation$Builder ((fn [builder id]
                                   (.invoke bulk-builder-id builder (into-array Object [id])))
                                 &quot;test-id&quot;)
        (.document {&quot;test-document&quot; 123})
        (.build))))

(comment
  (bug)
  (workaround))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When this namespace is loaded with Clojure 1.11.1, it gives the following reflection warnings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Reflection warning, .../example.clj:6:7 - call to method index on org.opensearch.client.opensearch.core.bulk.IndexOperation$Builder can't be resolved (argument types: java.lang.String).
Reflection warning, .../example.clj:7:7 - call to method id can't be resolved (target class is unknown).
Reflection warning, .../example.clj:8:7 - call to method document can't be resolved (target class is unknown).
Reflection warning, .../example.clj:9:7 - reference to field build can't be resolved.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And when the bug function is executed, it fails with the exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error (IllegalArgumentException) at example/bug (example.clj:6).
Can't call public method of non-public class: public final org.opensearch.client.opensearch.core.bulk.BulkOperationBase$AbstractBuilder org.opensearch.client.opensearch.core.bulk.BulkOperationBase$AbstractBuilder.index(java.lang.String)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;IndexOperation$Builder&lt;/code&gt; is a public class, which extends the protected abstract class &lt;code&gt;WriteOperation$AbstractBuilder&lt;/code&gt;, which extends the protected abstract class &lt;code&gt;BulkOperationBase$AbstractBuilder&lt;/code&gt;. The &lt;code&gt;index&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; methods' return type is a class-level type parameter, but the method arguments are non-generic.&lt;/p&gt;
&lt;p&gt;Here are the relevant places in the library code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/opensearch-project/opensearch-java/blob/52679c34cc4ce01bd01e4b2a380cb27a9046e953/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/IndexOperation.java#L100&quot;&gt;IndexOperation$Builder type signature&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/opensearch-project/opensearch-java/blob/52679c34cc4ce01bd01e4b2a380cb27a9046e953/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/WriteOperation.java#L96-L98&quot;&gt;WriteOperation$AbstractBuilder type signature&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/opensearch-project/opensearch-java/blob/52679c34cc4ce01bd01e4b2a380cb27a9046e953/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/BulkOperationBase.java#L192&quot;&gt;BulkOperationBase$AbstractBuilder type signature&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/opensearch-project/opensearch-java/blob/52679c34cc4ce01bd01e4b2a380cb27a9046e953/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/BulkOperationBase.java#L219-L230&quot;&gt;BulkOperationBase$AbstractBuilder method signatures&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/4255/cannot-resolve-public-generic-method-package-private-class?show=12483#a12483</guid>
<pubDate>Fri, 16 Dec 2022 10:39:39 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=12363#a12363</link>
<description>&lt;p&gt;In the inline code, replace &lt;code&gt;(put. env val)&lt;/code&gt; with &lt;code&gt;(.put env val)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In the code block, replace &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;doseq&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But that won't solve the exception. It seems like you're hitting either &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-1243&quot;&gt;https://clojure.atlassian.net/browse/CLJ-1243&lt;/a&gt; (even though the description is not entirely the same, the root cause might be) or something very similar, and I can also reproduce it.&lt;/p&gt;
&lt;p&gt;In order to fix it, add a type annotation: &lt;code&gt;(.put ^java.util.Map environment env val)&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?show=12363#a12363</guid>
<pubDate>Sun, 06 Nov 2022 15:49:16 +0000</pubDate>
</item>
<item>
<title>Answered: Java method overloaded</title>
<link>https://ask.clojure.org/index.php/12208/java-method-overloaded?show=12209#a12209</link>
<description>&lt;pre&gt;&lt;code&gt;user=&amp;gt; (vec (.getBytes &quot;ᵶ&quot; &quot;latin1&quot;))
[63]
user=&amp;gt; (vec (.getBytes &quot;ᵶ&quot;))
[-31 -75 -74]
user=&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you don't pass an argument then clojure will call the one that doesn't take an argument.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12208/java-method-overloaded?show=12209#a12209</guid>
<pubDate>Fri, 16 Sep 2022 17:40:29 +0000</pubDate>
</item>
<item>
<title>Answered: Could deftype allow for overriding methods?</title>
<link>https://ask.clojure.org/index.php/12113/could-deftype-allow-for-overriding-methods?show=12121#a12121</link>
<description>&lt;p&gt;Did you actually try this? Because it seems to work for me now.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(deftype MyIterator []
  java.util.Iterator
  (hasNext [this] false)
  (next [this] 0)
  ;; try to override default method
  (remove [this] (println &quot;boo&quot;)))

(.remove (MyIterator.))
;; boo
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12113/could-deftype-allow-for-overriding-methods?show=12121#a12121</guid>
<pubDate>Thu, 18 Aug 2022 21:15:52 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=12077#a12077</link>
<description>&lt;p&gt;You can see the list of default imports here: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/clojure-1.11.1/src/jvm/clojure/lang/RT.java#L39&quot;&gt;https://github.com/clojure/clojure/blob/clojure-1.11.1/src/jvm/clojure/lang/RT.java#L39&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I only see 2 nested classes: &lt;code&gt;Thread$UncaughtExceptionHandler&lt;/code&gt; and &lt;code&gt;Thread$State&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It's static so I guess it should only include classes that are available in every supported java versions.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12060/runtime-version-nested-class-jdk-not-automatically-imported?show=12077#a12077</guid>
<pubDate>Wed, 27 Jul 2022 13:52:46 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=11969#a11969</link>
<description>&lt;p&gt;Okay, my mental model of &lt;code&gt;identical?&lt;/code&gt; is not accurate. It calls &lt;code&gt;clojure.lang.Util/identical&lt;/code&gt; which has the following implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static public boolean identical(Object k1, Object k2){
    return k1 == k2;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When Clojure calls a function with such signature, it has to box the primitive values in the arguments. Doubles are boxed by calling &lt;code&gt;Double.valueOf(double)&lt;/code&gt;. The unusual equality semantics of NaN make the examples confusing, but in every case, &lt;code&gt;identical?&lt;/code&gt; compares the reference equality of boxed values, not numerical equality.&lt;/p&gt;
&lt;p&gt;By looking at disassembled byte code (see below), we can see what's happening. Here's summary.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In examples 1, 2, and 4, each of the arguments to &lt;code&gt;identical?&lt;/code&gt; is boxed individually.&lt;/li&gt;
&lt;li&gt;In example 3, &lt;code&gt;##NaN&lt;/code&gt; is boxed only once and the same boxed value is used as the both arguments of &lt;code&gt;identical?&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are a few more examples. Note that the behavior of &lt;code&gt;##Inf&lt;/code&gt; matches that of &lt;code&gt;##NaN&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(identical? ##Inf ##Inf)          ; true
(let [x ##Inf] (identical? x x))  ; false

(identical? 1.0 1.0)              ; false
(let [x 1.0] (identical? x x))    ; false

(def my-one 1.0)
(identical? my-one my-one)        ; true
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Everything works as it should. My mental model about &lt;code&gt;identical?&lt;/code&gt; was wrong. It's more like &lt;code&gt;(Object)... == (Object) ...&lt;/code&gt; than plain &lt;code&gt;==&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lesson learned:&lt;/strong&gt;  Use &lt;code&gt;identical?&lt;/code&gt; only for reference equality.&lt;/p&gt;
&lt;h2&gt;Disassembled examples&lt;/h2&gt;
&lt;p&gt;The code has been disassembled with &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure-goes-fast/clj-java-decompiler&quot;&gt;clj-java-decompiler&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Example 1 &lt;code&gt;(identical? Double/NaN Double/NaN)&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;class user$fn_line_1__254
    Minor version: 0
    Major version: 52
    Flags: PUBLIC, FINAL, SUPER
    
    public void &amp;lt;init&amp;gt;();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: aload_0        
               1: invokespecial   clojure/lang/AFunction.&amp;lt;init&amp;gt;:()V
               4: return         
    
    public static java.lang.Object invokeStatic();
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: getstatic       java/lang/Double.NaN:D
               3: invokestatic    java/lang/Double.valueOf:(D)Ljava/lang/Double;
                  linenumber      1
               6: getstatic       java/lang/Double.NaN:D
               9: invokestatic    java/lang/Double.valueOf:(D)Ljava/lang/Double;
                  linenumber      1
              12: invokestatic    clojure/lang/Util.identical:(Ljava/lang/Object;Ljava/lang/Object;)Z
              15: ifeq            24
              18: getstatic       java/lang/Boolean.TRUE:Ljava/lang/Boolean;
              21: goto            27
              24: getstatic       java/lang/Boolean.FALSE:Ljava/lang/Boolean;
              27: areturn        
        StackMapTable: 00 02 18 42 07 00 1D
    
    public java.lang.Object invoke();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: invokestatic    user$fn_line_1__254.invokeStatic:()Ljava/lang/Object;
               3: areturn        
    
    static {};
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: return         
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Example 2 &lt;code&gt;(let [x Double/NaN] (identical? x x))&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Skipped; similar to example 4.&lt;/p&gt;
&lt;h3&gt;Example 3 &lt;code&gt;(identical? ##NaN ##NaN)&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Note that the boxing happens in the static block.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class user$fn_line_1__246
    Minor version: 0
    Major version: 52
    Flags: PUBLIC, FINAL, SUPER
    
    public static final java.lang.Object const__1;
        Flags: PUBLIC, STATIC, FINAL
    
    public void &amp;lt;init&amp;gt;();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: aload_0        
               1: invokespecial   clojure/lang/AFunction.&amp;lt;init&amp;gt;:()V
               4: return         
    
    public static java.lang.Object invokeStatic();
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: getstatic       user$fn_line_1__246.const__1:Ljava/lang/Object;
               3: getstatic       user$fn_line_1__246.const__1:Ljava/lang/Object;
                  linenumber      1
               6: invokestatic    clojure/lang/Util.identical:(Ljava/lang/Object;Ljava/lang/Object;)Z
               9: ifeq            18
              12: getstatic       java/lang/Boolean.TRUE:Ljava/lang/Boolean;
              15: goto            21
              18: getstatic       java/lang/Boolean.FALSE:Ljava/lang/Boolean;
              21: areturn        
        StackMapTable: 00 02 12 42 07 00 17
    
    public java.lang.Object invoke();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: invokestatic    user$fn_line_1__246.invokeStatic:()Ljava/lang/Object;
               3: areturn        
    
    static {};
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: ldc2_w          NaN
               3: invokestatic    java/lang/Double.valueOf:(D)Ljava/lang/Double;
               6: putstatic       user$fn_line_1__246.const__1:Ljava/lang/Object;
               9: return         
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Example 4 &lt;code&gt;(let [x ##NaN] (identical? x x))&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Note two &lt;code&gt;Double.valueOf&lt;/code&gt; calls in the invokeStatic method.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class user$fn_line_1__250
    Minor version: 0
    Major version: 52
    Flags: PUBLIC, FINAL, SUPER
    
    public void &amp;lt;init&amp;gt;();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: aload_0        
               1: invokespecial   clojure/lang/AFunction.&amp;lt;init&amp;gt;:()V
               4: return         
    
    public static java.lang.Object invokeStatic();
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: ldc2_w          NaN
               3: dstore_0        /* x */
               4: dload_0         /* x */
               5: invokestatic    java/lang/Double.valueOf:(D)Ljava/lang/Double;
               8: dload_0         /* x */
               9: invokestatic    java/lang/Double.valueOf:(D)Ljava/lang/Double;
                  linenumber      1
              12: invokestatic    clojure/lang/Util.identical:(Ljava/lang/Object;Ljava/lang/Object;)Z
              15: ifeq            24
              18: getstatic       java/lang/Boolean.TRUE:Ljava/lang/Boolean;
              21: goto            27
              24: getstatic       java/lang/Boolean.FALSE:Ljava/lang/Boolean;
              27: areturn        
        StackMapTable: 00 02 FC 00 18 03 42 07 00 1B
    
    public java.lang.Object invoke();
        Flags: PUBLIC
        Code:
                  linenumber      1
               0: invokestatic    user$fn_line_1__250.invokeStatic:()Ljava/lang/Object;
               3: areturn        
    
    static {};
        Flags: PUBLIC, STATIC
        Code:
                  linenumber      1
               0: return         
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11963/identical-treat-bound-nan-differently-direct-reference?show=11969#a11969</guid>
<pubDate>Tue, 14 Jun 2022 19:29:03 +0000</pubDate>
</item>
<item>
<title>Answered: Could realized? support Java futures?</title>
<link>https://ask.clojure.org/index.php/11913/could-realized-support-java-futures?show=11915#a11915</link>
<description>&lt;p&gt;Whenever anyone brings up &lt;code&gt;realized?&lt;/code&gt; in discussions on Slack, the general advice is that you shouldn't use it and it already doesn't work in an intuitive way in many situations.&lt;/p&gt;
&lt;p&gt;The question then usually turns to &quot;Why are you using &lt;code&gt;realized?&lt;/code&gt; in the first place?&quot;.&lt;/p&gt;
&lt;p&gt;An example of non-intuitive behavior:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/10004/calling-realized-delay-currently-executing-blocks-caller&quot;&gt;https://ask.clojure.org/index.php/10004/calling-realized-delay-currently-executing-blocks-caller&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(considered a bug -- fixed in Clojure 1.11)&lt;/p&gt;
&lt;p&gt;I just checked our 125k line codebase and there's just one call to &lt;code&gt;realized?&lt;/code&gt; in a test, specifically checking whether a &lt;code&gt;promise&lt;/code&gt; was &lt;code&gt;deliver&lt;/code&gt;ed or not.&lt;/p&gt;
&lt;p&gt;I'll be interested to hear what folks from the Clojure Team say about this but I suspect they wouldn't want to encourage use of it?&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11913/could-realized-support-java-futures?show=11915#a11915</guid>
<pubDate>Sat, 28 May 2022 20:14:05 +0000</pubDate>
</item>
<item>
<title>Answered: Integration with java.util.function interfaces</title>
<link>https://ask.clojure.org/index.php/767/integration-with-java-util-function-interfaces?show=11910#a11910</link>
<description>&lt;p&gt;This is what a Kafka Streams app written in Java looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;      sb.table(&quot;input&quot;, Consumed.with(sl, sl))
            .groupBy((k, v) -&amp;gt; KeyValue.pair(k / 10, v), Grouped.with(sl, sl))
            .aggregate(() -&amp;gt; 0L,
                    (k, v, acc) -&amp;gt; acc + v,
                    (k, v, acc) -&amp;gt; acc - v,
                    Materialized.with(sl, sl))
            .toStream()
            .to(&quot;output&quot;, Produced.with(sl, sl));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same app written in Clojure looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    (-&amp;gt; sb
        (.table &quot;input&quot; (topic-&amp;gt;consumed data-in))
        (.groupBy (key-value-mapper
                    (fn [k v] (KeyValue/pair (long (/ k 10)) v)))
                (serdes-&amp;gt;grouped &quot;groupie&quot; data-in))
        (.aggregate (reify Initializer
                    (apply [_] 0))
                    (reify Aggregator
                    (apply [_ k v acc]
                        (+ acc v)))
                    (reify Aggregator
                    (apply [_ k v acc]
                        (- acc v)))
                    (serdes-&amp;gt;materialised ...))
        (.toStream)
        (.to &quot;output&quot; (topic-&amp;gt;produced data-out)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we had the ability to use Lambdas where SAM types are expected, we could write this instead:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    (-&amp;gt; sb
        (.table &quot;input&quot; (topic-&amp;gt;consumed data-in))
        (.groupBy (fn [k v] (KeyValue/pair (long (/ k 10)) v))
                (serdes-&amp;gt;grouped &quot;groupie&quot; data-in))
        (.aggregate (constantly 0)
                    (fn [k v acc] (+ acc v))
                    (fn [k v acc] (- acc v))
                    (serdes-&amp;gt;materialised ...))
        (.toStream)
        (.to &quot;output&quot; (topic-&amp;gt;produced data-out)))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/767/integration-with-java-util-function-interfaces?show=11910#a11910</guid>
<pubDate>Thu, 26 May 2022 11:59:10 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=11861#a11861</link>
<description>&lt;p&gt;&lt;code&gt;(def foo &quot;bar&quot;)&lt;/code&gt; creates a &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/vars&quot;&gt;Clojure var&lt;/a&gt; - technically a &lt;em&gt;mutable&lt;/em&gt; form of storage.&lt;/p&gt;
&lt;p&gt;There is no guarantee (implicit or explicit) that the code won't do something like &lt;code&gt;(alter-var-root #'foo #(do % 42))&lt;/code&gt; unless someone provides hints. That would make it difficult to do implicit type inference in the core language.&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?show=11861#a11861</guid>
<pubDate>Thu, 05 May 2022 09:40:34 +0000</pubDate>
</item>
<item>
<title>Answered: Incorrect long quot result involving Long/MIN_VALUE</title>
<link>https://ask.clojure.org/index.php/1177/incorrect-long-quot-result-involving-long-minvalue?show=11530#a11530</link>
<description>&lt;p&gt;Also see &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/11521/some-corner-cases-that-might-considered-ratio-implementation&quot;&gt;https://ask.clojure.org/index.php/11521/some-corner-cases-that-might-considered-ratio-implementation&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/1177/incorrect-long-quot-result-involving-long-minvalue?show=11530#a11530</guid>
<pubDate>Mon, 31 Jan 2022 17:13:26 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=11416#a11416</link>
<description>&lt;p&gt;If you prefer an interactive chat experience for asking  such questions, the #beginners channel on the Clojurians Slack community at &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians.slack.com&quot;&gt;https://clojurians.slack.com&lt;/a&gt; is a good place for such questions.  Either here or there, it can be helpful if you are willing to publish longer code samples you are working on in a public place such as Github.com.&lt;/p&gt;
&lt;p&gt;To your questions, your first function &lt;code&gt;pt%%&lt;/code&gt; assigns a value to &lt;code&gt;val&lt;/code&gt; before the loop begins, and then &lt;code&gt;val&lt;/code&gt; always has the same value from that point onwards, never changing.  Thus regardless of what is done inside of the loop, it will be an infinite loop, unless an exception occurs, which is what happens in your case.  I have not tried to diagnose exactly why that particular exception occurs, because of the infinite loop issue and &lt;code&gt;val&lt;/code&gt; never changing.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;pt5&lt;/code&gt; has the same issue that &lt;code&gt;val&lt;/code&gt; is always the same, because &lt;code&gt;(recur val)&lt;/code&gt; occurs in a context where &lt;code&gt;val&lt;/code&gt; is bound to the same value as when the loop began.&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;pt5&lt;/code&gt;, try using &lt;code&gt;val&lt;/code&gt; as an argument to the &lt;code&gt;tocChars&lt;/code&gt; method, and change the &lt;code&gt;recur&lt;/code&gt; expression to &lt;code&gt;(recur (.read bfr))&lt;/code&gt; and see how that goes.  And think about why that behaves differently than your version in the question.&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?show=11416#a11416</guid>
<pubDate>Sun, 26 Dec 2021 18:13:41 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=10679#a10679</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2635&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2635&lt;/a&gt;&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?show=10679#a10679</guid>
<pubDate>Tue, 08 Jun 2021 15:10:01 +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>Answered: into-array should not need type hints</title>
<link>https://ask.clojure.org/index.php/10609/into-array-should-not-need-type-hints?show=10614#a10614</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2631&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2631&lt;/a&gt;&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?show=10614#a10614</guid>
<pubDate>Sun, 16 May 2021 13:52:18 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=10559#a10559</link>
<description>&lt;p&gt;For reference, it looks like clojure.tools.emitter.jvm DOES preserve the type of non-primitive fields....&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (require '[clojure.tools.emitter.jvm :as e])

(e/eval '(deftype blah [^String x]) {:debug? true})
;;;
// class version 50.0 (50)
// access flags 0x31
public final class user/blah implements clojure/lang/IType  {

  // compiled from: user/blah

  // access flags 0x11
  public final Ljava/lang/String; x
...

user&amp;gt; (require '[clojure.reflect :as r])
nil
user&amp;gt; (r/reflect (user.blah. &quot;hello&quot;))
{:bases #{java.lang.Object clojure.lang.IType},
 :flags #{:public :final},
 :members
 #{{:name getBasis,
    :return-type clojure.lang.IPersistentVector,
    :declaring-class user.blah,
    :parameter-types [],
    :exception-types [],
    :flags #{:public :static}}
   {:name user.blah,
    :declaring-class user.blah,
    :parameter-types [java.lang.Object],
    :exception-types [],
    :flags #{:public}}
   {:name x,
    :type java.lang.String,  ;;in clojure
    :declaring-class user.blah,
    :flags #{:public :final}}}}
&lt;/code&gt;&lt;/pre&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?show=10559#a10559</guid>
<pubDate>Sun, 02 May 2021 07:38:25 +0000</pubDate>
</item>
<item>
<title>Answered: Problems loading ffmpeg library with jna</title>
<link>https://ask.clojure.org/index.php/10128/problems-loading-ffmpeg-library-with-jna?show=10395#a10395</link>
<description>&lt;p&gt;In the meantime: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/cnuernber/avclj&quot;&gt;https://github.com/cnuernber/avclj&lt;/a&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10128/problems-loading-ffmpeg-library-with-jna?show=10395#a10395</guid>
<pubDate>Fri, 02 Apr 2021 09:03:41 +0000</pubDate>
</item>
<item>
<title>Answered: Apparently uncallable method overload</title>
<link>https://ask.clojure.org/index.php/10318/apparently-uncallable-method-overload?show=10319#a10319</link>
<description>&lt;p&gt;looks a lot like &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-1243&quot;&gt;https://clojure.atlassian.net/browse/CLJ-1243&lt;/a&gt;, the addAll(RangeSet ...) method is defined in a package private class &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/google/guava/blob/v30.1/android/guava/src/com/google/common/collect/AbstractRangeSet.java&quot;&gt;https://github.com/google/guava/blob/v30.1/android/guava/src/com/google/common/collect/AbstractRangeSet.java&lt;/a&gt;. There is also an interface(&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/google/guava/blob/v30.1/android/guava/src/com/google/common/collect/RangeSet.java&quot;&gt;https://github.com/google/guava/blob/v30.1/android/guava/src/com/google/common/collect/RangeSet.java&lt;/a&gt;), but all the methods there lack access modifiers, so are private (not sure what that does to java inheritance)  &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10318/apparently-uncallable-method-overload?show=10319#a10319</guid>
<pubDate>Mon, 08 Mar 2021 20:26:34 +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>Answered: 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?show=9965#a9965</link>
<description>&lt;p&gt;You explicitly asked for a JNR-FFI solution, but there are alternative Clojure libraries not based on JNR-FFI that allow you to do what you want. Have a look at:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Chouser/clojure-jna&quot;&gt;https://github.com/Chouser/clojure-jna&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/techascent/tech.jna&quot;&gt;https://github.com/techascent/tech.jna&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Both can do what you want by using JNA under the hood (not using JNR-FFR).&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?show=9965#a9965</guid>
<pubDate>Wed, 23 Dec 2020 00:15:30 +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>
</channel>
</rss>