java - Should I use "this" keyword when I want to refer to instance variables within a method? -
my teacher says when try access instance variable within method should use this
keyword, otherwise perform double search. local scope search , instance scope search.
example:
public class test(){ int cont=0; public void method(){ system.out.println(cont);//should use this.cont instead? } }
i hope wrong, can't find argument.
no, use this
when have name conflict such when method parameter has same name instance field setting.
it can used @ other times, many of feel adds unnecessary verbiage code.
Comments
Post a Comment