Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Compiler by

Jetty's BlockingArrayQueue has these two constructors (among a bunch of others):

/**
 * 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 = "12.1.2", 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 < 0 || maxCapacity < 0 || capacity > maxCapacity)
        throw new IllegalArgumentException();
    _elements = new Object[capacity];
    _maxCapacity = maxCapacity;
}

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.

(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')

What am I doing wrong?

1 Answer

0 votes
ago by

That constructor is private, you can't call it.

ago by
And looking at the source code in full, it looks like (BlockingArrayQueue/newInstance 5 10) is what is wanted going forward since both of the "growth" constructors are deprecated. Note that capacity (5) must be no greater than maxCapacity (10).
ago by
omg, that was right in my face, staring at me and I could not see it! thank you, Alex!
...