When I use JLabel string comparison with ==
works fine
private JLabel someJLabel = new JLabel("some text");
...
System.out.println (someJLabel.getText() == "some text"); // returns true
but when I use JTextField
private JTextField someJTextField = new JTextField("some text");
...
System.out.println (someJTextField.getText() == "some text"); // returns false
I know that if I used someJTextField.getText().equals("some text");
it would work fine.
So why it works with JLabel but not JTextField
EDIT: yes I know that I should use .equals
with string, I have read this article http://javatechniques.com/blog/string-equality-and-interning/ but it's known already that I will use "some text" so it could refer to same string object