Jump to content

Cant figure out a boolean

Recommended Posts

3 minutes ago, payton9812 said:

I can't figure out why this is always returning false...
    private boolean atBankPosition()
        Position pos = new Position(3185, 3444, 0);

 if (myPosition()equals(pos)) return true; else return false;



Any help?

Use equals() and not ==, that is

 if (myPosition()equals(pos)) return true; else return false;

This is because == checks if two objects ARE THE SAME IN MEMORY, which they are not.

equals(), if coded properly, checks the values of the objects and that is what you need

Edited by Butters
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...