-1

So, I'm trying to do something really simple, and that's check if a password equals something in my SWT application. So, my code was this:

if (passwordBox.getText() == "test") {
    passwordBox.setVisible(false);
}

However, in my application, which uses text fields marked as passwords (with that variable), it will not fire that when I click a button. I already have button handling working, since I have an else statement that fires, but this will not fire when the password box obviously equals "test". What's wrong here?

1 Answers1

1

Strings are always compared by equals().

if(("test").equals(passwordBox.getText())) {
   passwordBox.setVisible(false);
}
Shashwat
  • 2,342
  • 1
  • 17
  • 33