I have a class I am implementing called a Deque. Deque has a method called ensureCapacity that increases the size of the array holding the deque automatically.
I would expect the method to return a new Deque with the old Deque inserted into the middle of the new array. However the compiler complains and says:
ensureCapacity(Deque) in Deque cannot be applied to (java.lang.Object[])
elementData = ensureCapacity(elementData);
What have I done wrong here? Thanks for any help.
03-05-2003, 07:13 AM
MasterOfSouls
Well, I don't know too much about increasing sizes of arrays and things like that, but the error message you got means that you cannot use that class to increase the size of an array for an object. Maybe if you try to pass the Deque instead as an array of integers it might work. What exactly does the Deque object hold? Maybe there's a better way of doing it... Hope this helps!
03-17-2003, 01:26 PM
ArchAngel
Check what type of variable elementData is. From the compile error I'm guessing it's an array. This will not work as the method expects a single reference.
03-19-2003, 04:02 AM
nick
if you want to change the size of an array, you might wanna try using the Vector class. it's an unlimited array.
you can read about it somewhere in the beginner tutorials here in the site which is called "java by example"
03-19-2003, 04:20 AM
ArchAngel
...or java.util.ArrayList. It's more efficient than Vector (it's all to do with synchronzing in multi-threaded code).