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.
Re: Evaluate a reference object?
Code:
Object obj = maybeReturnObject();
if(obj == null) {
Re: Evaluate a reference object?
So
if (MyObject varname == null)
Is valid?
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();
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.