<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged java interop</title>
<link>https://ask.clojure.org/index.php/tag/java+interop</link>
<description></description>
<item>
<title>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>cannot call Java Constructor overload</title>
<link>https://ask.clojure.org/index.php/14744/cannot-call-java-constructor-overload</link>
<description>&lt;p&gt;Jetty's &lt;code&gt;BlockingArrayQueue&lt;/code&gt; has these two constructors (among a bunch of others):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**
 * Creates an instance with given initial and max capacities.
 *
 * @param capacity the initial capacity
 * @param growBy the growth factor
 * @param maxCapacity the maximum capacity
 * @deprecated the growth factor isn't used anymore
 */
@Deprecated(since = &quot;12.1.2&quot;, forRemoval = true)
public BlockingArrayQueue(int capacity, int growBy, int maxCapacity)
{
    this(capacity, maxCapacity, false);
}

/**
 * Creates an instance with given initial and max capacities.
 *
 * @param capacity the initial capacity
 * @param maxCapacity the maximum capacity
 * @param ignored this parameter is ignored but is needed as there is already a
 *  {@link BlockingArrayQueue#BlockingArrayQueue(int, int) deprecated constructor} that takes two ints.
 */
private BlockingArrayQueue(int capacity, int maxCapacity, boolean ignored)
{
    if (capacity &amp;lt; 0 || maxCapacity &amp;lt; 0 || capacity &amp;gt; maxCapacity)
        throw new IllegalArgumentException();
    _elements = new Object[capacity];
    _maxCapacity = maxCapacity;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I'm trying to call the second (the one with the boolean arg in the third position) but the compiler is hell bent on calling the first one.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(BlockingArrayQueue. 10 5 true)
Execution error (ClassCastException) at user/eval7644 (form-init275792826230635171.clj:1).
class java.lang.Boolean cannot be cast to class java.lang.Number (java.lang.Boolean and java.lang.Number are in module java.base of loader 'bootstrap')

(BlockingArrayQueue. 10 5 (boolean true))
Execution error (ClassCastException) at user/eval7648 (form-init275792826230635171.clj:1).
class java.lang.Boolean cannot be cast to class java.lang.Number (java.lang.Boolean and java.lang.Number are in module java.base of loader 'bootstrap')

(BlockingArrayQueue. 10 5 Boolean/TRUE)
Execution error (ClassCastException) at user/eval7652 (form-init275792826230635171.clj:1).
class java.lang.Boolean cannot be cast to class java.lang.Number (java.lang.Boolean and java.lang.Number are in module java.base of loader 'bootstrap')
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What am I doing wrong?&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14744/cannot-call-java-constructor-overload</guid>
<pubDate>Mon, 03 Nov 2025 18:05:31 +0000</pubDate>
</item>
</channel>
</rss>