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

Thread: Empty If Statement

  1. #1
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Empty If Statement

    So I'm new to these forums, and I was going to do an introduction first, but than I ran over something that really confused me, and I want to know more about it. So I was reading through some decompiled Minecraft code, and I came across this:

    if (!(new WorldGenDungeons()).generate(worldObj, rand, k2, k3, i4));

    So as I see it, generate returns whether or not a dungeon has successfully made. So what is the purpose of this statement? If it helps, this is at the end of a for loop that runs 8 times.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Empty If Statement

    You'll have to ask the author of the code why he wrote that statement to get its purpose.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Empty If Statement

    Since I can't contact the author easily, let me rephrase the question...Doesn't that statement do nothing? I don't see how that statement could get anything accomplished.

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: Empty If Statement

    I'm not too sure about that either, quite strange. I've never seen anybody purposely write something like that.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Empty If Statement

    It looks like it creates an instance of a class and calls a method of that class which returns a boolean value used by the if statement to control execution flow.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Empty If Statement

    It creates the instance of the class and calls the generate function, but the actual boolean value looks like it is discarded, as the if statement doesn't do anything. This is confusing...Though this code was written back in...I don't know...Infdev? When Notch was just programming it by himself and had really bad habit.
    Last edited by lightOfDay; June 14th, 2012 at 09:30 AM.

Similar Threads

  1. How to not accept empty jfield?
    By myexternall11 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 20th, 2012, 04:38 AM
  2. first empty location in an array!?
    By keep smiling in forum Collections and Generics
    Replies: 2
    Last Post: February 10th, 2012, 07:29 AM
  3. [SOLVED] find first empty cell?
    By prettynew in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 15th, 2011, 11:52 AM
  4. empty response received
    By grashmi13 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 16th, 2010, 05:30 PM
  5. [SOLVED] Supressing empty lines and does not do until the end! Why ?
    By lumpy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 07:38 AM