This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have created my own Queue class, along with a Linear Linked list class, and a node class. A Linear Linked list contains Nodes, with a single character as a value, and a link pointing to the next node. The Queue class just contains a Linear Linked list. Now, I store each character in a node by using the new Character() wrapper class. When I pull out values from my queue, i can't cast them as characters. I get the error message "inconvertable types". And I do not want to store anything but Objects inside my nodes, because it gives flexibility. Why can't I cast an object to char? I didn't seem to have a problem storing a char as an object. Please don't ask me to post code, because all it is, is char c = queue.pop(), where pop returns an object.
Now, I store each character in a node by using the new Character() wrapper class. When I pull out values from my queue, i can't cast them as characters.
Well, you have two options. You can use autoboxing, but it will need some help. It doesn't know that it is a Character object, so you will need to cast it to a Character object and let autoboxing take care of the rest. Like so...
Or you can take care of the unboxing yourself -- after all, you boxed it with Character wrapper class yourself.