Results 1 to 3 of 3
Like Tree2Likes
  • 1 Post By pbrockway2
  • 1 Post By DarrylBurke

Thread: What does -1 mean in java??

  1. #1
    ssk2659 is offline Member
    Join Date
    Jan 2015
    Posts
    48
    Rep Power
    0

    Default What does -1 mean in java??

    hey folks, I've seen in examples return of -1 or statement == -1. for example, let's say:
    Java Code:
    if(position[exams[i].getID()]==-1){
    
    .....statements
    }
    else
    ....
    So what does equatting to -1 mean mean or give ?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    18

    Default Re: What does -1 mean in java??

    People often given "strange" values a special meaning. For example if id values are expected to be positive the author of the getID() method may intend the -1 value to mean "an id has not yet be assigned". It's up to the author of that code to say what it means by documenting it clearly. If you write code where some return values are special, remember to include a description of what the values mean in the relevant javadocs.
    ssk2659 likes this.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: What does -1 mean in java??

    Quote Originally Posted by pbrockway2 View Post
    It's up to the author of that code to say what it means by documenting it clearly.
    And here's an example of that.

    db
    ssk2659 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •