Lame Java Question

bex0rs

Golden Member
Oct 20, 2000
1,291
0
0
This one is pretty basic, but for some reason I'm being kind of dense right now.

If I have a method, say removeLast() in the class LinkedList, which, according to Sun's specs, removes the last element from a LinkedList and returns it, does that mean I must do something like this:

Object blah = myLinkedList.removeLast();

or can I just do this:

myLinkedList.removeLast();

since I don't care about what the last object is. I just want to ditch it and there is no need to save it.

Thanks!

~bex0rs
 

BearX00

Senior member
Nov 28, 2000
208
0
0
yes what you should do then is the second choice since you dont care what the last element was then you may just want to discard the results. why even create another object to hold somethignthat you dont even want in the end. Although it may be needed later, but it just seems like you dont care about it so just ditch it.
hope that helps
 

bex0rs

Golden Member
Oct 20, 2000
1,291
0
0
That was what I was suspecting, and I just verified it. So I guess that even though removeLast() returns an Object, I don't need to explicitly code what to do with it. Thanks!

~bex0rs
 

joinT

Lifer
Jan 19, 2001
11,172
0
0
beX0rs, how skilled are you @ java ??
I'm working w/ Cold Fusion & want to chat w/ someone about ways to utilize the 2 effectively.

shoot me a PM :)
 

IcemanJer

Diamond Member
Mar 9, 2001
4,307
0
0
if you don't give it (the returned object) an assignment in the current stack, it'll just be garbage collected, which is what you want to do anyways.