r/javahelp • u/dg_713 • Sep 12 '19
What is the difference between "[ClassName].this.variable" and simply, "this.variable"
So I came across this class called:
AutoCompleteComboBoxListener()
with a node called comboBox.
And inside its methods, such as
selectClosestResultBasedOnTextFieldValue(),
they refer to the comboBox of AutoCompleteComboBoxListener() as
AutoCompleteComboBoxListener.this.comboBox.getItems();
Is it different from:
this.comboBox.getItems();
Thanks a lot everyone.
17
Upvotes
2
u/HBK05 Sep 12 '19
This refers to the current class, if you are already working in that class, there's no real point to use it besides coding conventions, some people swear you should use it for cleanness and easy/understandable code, and some don't care.
The keyword
supercan be used to refer to a variable that is inherited into the current class, but does not actually reside in said class. It's basically the other end to that, in-case you have the same variable name in an inherited class and the local class (for some reason..) you save yourself from that confusion.