Results 1 to 3 of 3
  1. #1
    rhm54 is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default Type Casting Help

    I believe this is a problem with Type casting but I am not sure. I have a LinkedList class that I have created which stores nodes of type Object. I am building a print queue that uses the list and stores an Object of type printdata in the nodes. This line of code here gives me the following error message:

    Type mismatch: cannot convert from Object to PriorityQ.printdata

    printdata temp = L1.getNode(0);

    I assume that I need to type cast but I don't know how.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    stores an Object of type printdata
    Try declaring/adding this "printdata" as the type instead of Object.
    Java Code:
    LinkedList<printdata> list = ...

  3. #3
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Casting

    Hello rhm54

    Try the following cast:
    Java Code:
    printdata temp =[COLOR="RoyalBlue"] (printdata) [/COLOR]L1.getNode(0);
    I hope this does the trick. ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. Casting an int value into a char
    By kurtulas in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 09:03 PM
  2. 'Casting' couch !!!!
    By ajaygargnsit in forum Advanced Java
    Replies: 4
    Last Post: 01-04-2008, 05:54 PM
  3. 'Casting' couch !!
    By ajaygargnsit in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:05 PM
  4. Casting
    By leebee in forum New To Java
    Replies: 5
    Last Post: 08-10-2007, 01:24 PM
  5. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •