Should I use “this” keyword when I want to refer to instance variables within a method?

前端 未结 8 1797
北恋
北恋 2020-12-03 16:53

My teacher says that when I try to access an instance variable within a method I should always use the this keyword, otherwise I would perform a double search.

8条回答
  •  不思量自难忘°
    2020-12-03 17:43

    You must use this if required because of a name conflict, though it's better to avoid those entirely.

    You may use this if you desire. It is purely a matter of taste.

    You should use this in your schoolwork if your teacher demands it.

提交回复
热议问题