<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged constructor overload</title>
<link>https://ask.clojure.org/index.php/tag/constructor%20overload</link>
<description>Powered by Question2Answer</description>
<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&#039;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&#039;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&#039;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 &#039;bootstrap&#039;)

(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 &#039;bootstrap&#039;)

(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 &#039;bootstrap&#039;)
&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>