Jump to content

Cant figure out a boolean


Recommended Posts

Posted (edited)
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...