So I have this really large method I wrote. If it’s given a stack, it will return a stack. If it’s given a queue, it will return a queue. It uses a lot of recursion, and it accepts a queue/stack and returns that same queue/stack modified accordingly.
I don’t want to copy/paste my method just so I can change the type used inside, so is there any way I can make this generic? As in, it will accept any old collection and play with it? I tried just using Collection, but the trouble with that is it doesn’t have a .remove() I can use with the stack/queue.
Any help would be greatly appreciated.
Thanks.
You could use Collection but then have special case handling just around your remove operations. Of course you’ll have to figure out what to do when you get a collection that’s not one of the two.