|
-
Oct 1st, 2005, 12:13 PM
#1
Thread Starter
PowerPoster
Evaluate a reference object?
Is it possible to check a reference object variable to == null?
I am wondering how a linked list class can be written but if the nodes are an object... So how do I know when I hit the end? I would assume the usual check if the nextLink == null, if it does then your at the end.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Oct 2nd, 2005, 04:05 AM
#2
Re: Evaluate a reference object?
Code:
Object obj = maybeReturnObject();
if(obj == null) {
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 2nd, 2005, 12:42 PM
#3
Thread Starter
PowerPoster
Re: Evaluate a reference object?
So
if (MyObject varname == null)
Is valid?
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Oct 2nd, 2005, 01:35 PM
#4
Re: Evaluate a reference object?
No, you can't declare variables within an if-statement. But
MyObject var;
only declares a reference. It doesn't point to anything yet. Unlike C++, Java cannot create objects on the stack; you have to use new:
var = new MyObject();
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 3rd, 2005, 07:43 PM
#5
Thread Starter
PowerPoster
Re: Evaluate a reference object?
Yah I realize now after programming today that snipper was incorrect, but it was to sum it up... Anyway so I guess I shoulda simply asked in the first place if Java initializes your variable references to null upon creation?
object-type varname;
varname == null?
But they covered this in class today and indeed that is correct.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|