Reputation: 568
I'm trying to use an ArrayBlockingQueue but I cant seem to get the syntax right and I dont know what exactly I'm supposed to import to use it. I tried this:
BlockingQueue<int> Queue = new ArrayBlockingQueue<int>(100);
for the declaration but it says that there is an error with int "Dimensions expected after this token" for both of the ints. I feel like this is probably simple to solve, I may have just not imported to correct thing or my syntax is off, so any help is appreciated. Thanks
Upvotes: 0
Views: 64
Reputation: 31
You can't use atomic types as as the element it needs to be an object, try Integer.
BlockingQueue<Integer> Queue = new ArrayBlockingQueue<Integer>();
Upvotes: 0
Reputation: 200138
BlockingQueue<int>
Java Generics do not cover primitive types. You'll have to use Integer
instances.
This is an artifact of the type erasure approach taken by Java. You cannot erase an int
to an Object
and the actual bytecode needed to work with an int
is entirely different. That would only be possible if C++ approach was used to instantiate the template for each type parameter separately, as a new class with new bytecode.
Upvotes: 2