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
8
u/8igg7e5 Sep 12 '19
And it's worth noting that, if you declare a non-static inner class, every instance has the overhead of a link to the outer instance whether you actually use it or not - and if you let references to instances of the inner class escape, they prevent GC of the outer instance.
Use static inner classes unless you really need that outer class relationship.