File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting objects to char

 
John Lockheart
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Henry
 
John Lockheart
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I was using (char) as opposed to (Character). I haven't worked with simple primitives so long I guess I forgot.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic