• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting objects to char

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic