Testing Java Objects


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Testing Java Objects

  1. #1
    ABL456 Guest

    Testing Java Objects

    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



  2. #2
    Paul Clapham Guest

    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
    >
    >




  3. #3
    ABL456 Guest

    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
    > >
    > >

    >
    >




  4. #4
    Paul Clapham Guest

    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;
    > }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center