|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Class Casting Problem
Hey all. I'm sure this is a simple problem, but it's killing me right now. I have a linked list full of linked lists, and I want to be able to set a linked list inside the list of linked lists. So, I'm trying to get from the larget linked list, cast the returned result as a linkedlist, and then set it, like so...
Code:
public void setTeam(LinkedList aTeam, int teamIndex) {
( (LinkedList)(teams.get(teamIndex)) ).set(aTeam);
LinkedList test = ( (LinkedList)(teams.get(teamIndex)) );
}
This gives me a "cannot resolve symbol" error. The really frustrating thing is, it pukes on the first line of code, but the second is just fine, even though it's cast the same way! The only difference is, of course, the call to the set function of the newly cast linked list. Can anyone tell me what I'm doing wrong? Thanks in advance! -Cameron |
|
#2
|
|||
|
|||
|
Re: Class casting Problem
i guess the set method of LinkedList has two arguments... an integer specifying the index and the LinkedList object.. you have given only the latter..
Quote:
|
|
#3
|
|||
|
|||
|
try replacing the set line as:
( (LinkedList)(teams.get(teamIndex)) ).set(teamIndex,aTeam); Quote:
|
|
#4
|
||||
|
||||
|
If you still have problems, post your code please. LinkedList is not a standard java class but your own right?
I would recommend using arraylists with generics (java 1.5) by the way. |
|
#5
|
|||
|
|||
|
Haha, I knew it'd be something stupid! I guess my mind kept thinking I'd already gotten what I needed, so I wouldn't need to tell set what it was (which, of course, makes no sense now that I actually think about it). How embarassing... Anyway, thanks for the help, guys.
And Icon, LinkedList is a standard Java class. It's in java.util, I believe. |
|
#6
|
||||
|
||||
|
You're right, I was not sure about it anyway. Good luck
|
|
#7
|
||||
|
||||
|
Quote:
Go Tiger! =)
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Class Casting Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|