Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: nullify object

  1. #1
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default nullify object

    Is there any way I can nullify an object after having created it in a more generic sense rather than specifying its specific name.

    e.g. 'object one = new object()' can be nullified by 'one = null',
    instead of this I want something along the lines of 'this = null' in the constructor or introduce some break in the constructor to stop an object being created if a criteria is not met.

    How can I go about doing this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: nullify object

    Throw an exception.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following 2 Users Say Thank You to Norm For This Useful Post:

    keepStriving (December 4th, 2013), KevinWorkman (December 3rd, 2013)

  4. #3
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Re: nullify object

    I understand your advice though can't work me as I use an environment called bluej, where objects are created outside the program code so I can't really force the user to try use a try and catch when they simple create an instance of a class. Thank you for trying.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: nullify object

    can't really force the user to try use a try and catch when they simple create an instance of a class
    There are many examples in the Java SE. See the URL class for example.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: September 26th, 2013, 04:13 PM
  2. read & write object in object file
    By amirsarem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 8th, 2013, 11:35 AM
  3. static variable accessible in object b, not in object a?
    By Pajaro in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 30th, 2013, 02:41 PM
  4. Creating object everytime object is called
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2012, 04:18 PM
  5. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM