What's the best way to test whether an object has been instantiated or not?
I have a class and a few of the methods rely on an object that may or may
not have been instanced yet. I need to test the reference to the object to
ascertain it validity. Can anyone help.
-Jeff
04-05-2001, 11:51 AM
Paul Clapham
Re: Testing Java Objects
If an object has not been instantiated, then you can't have a reference to
it. In fact there is no "it". I find your question quite baffling -- maybe
you have a variable that can be assigned an object at some point and you
want to find out if that assignment has taken place? If so, compare it to
null:
if (theVariable == null)
PC2
"ABL456" <me@home.com> wrote in message news:3acb8f75$1@news.devx.com...
> What's the best way to test whether an object has been instantiated or
not?
> I have a class and a few of the methods rely on an object that may or may
> not have been instanced yet. I need to test the reference to the object to
> ascertain it validity. Can anyone help.
>
> -Jeff
>
>
04-05-2001, 06:06 PM
ABL456
Re: Testing Java Objects
Thanks PC. That's actually what I meant, sorry for the confusion. I just
want to check and see if the variable has been assigned yet. I guess
something like this.
SomeObject object_var;
If (object_var == null) {
object_var = new SomeObject;
}
- Jeff
"Paul Clapham" <pclapham@core-mark.com> wrote in message
news:3acc9429@news.devx.com...
> If an object has not been instantiated, then you can't have a reference to
> it. In fact there is no "it". I find your question quite baffling --
maybe
> you have a variable that can be assigned an object at some point and you
> want to find out if that assignment has taken place? If so, compare it to
> null:
>
> if (theVariable == null)
>
> PC2
>
> "ABL456" <me@home.com> wrote in message news:3acb8f75$1@news.devx.com...
> > What's the best way to test whether an object has been instantiated or
> not?
> > I have a class and a few of the methods rely on an object that may or
may
> > not have been instanced yet. I need to test the reference to the object
to
> > ascertain it validity. Can anyone help.
> >
> > -Jeff
> >
> >
>
>
04-05-2001, 06:40 PM
Paul Clapham
Re: Testing Java Objects
Yes, exactly.
PC2
"ABL456" <me@home.com> wrote in message news:3accec5a$1@news.devx.com...
> Thanks PC. That's actually what I meant, sorry for the confusion. I just
> want to check and see if the variable has been assigned yet. I guess
> something like this.
>
> SomeObject object_var;
>
> If (object_var == null) {
> object_var = new SomeObject;
> }