In Java, why do people prepend fields with `this`?

前端 未结 16 2146
广开言路
广开言路 2020-12-20 11:18

When referencing class variables, why do people prepend it with this? I\'m not talking about the case when this is used to disambiguate from method

16条回答
  •  北海茫月
    2020-12-20 11:47

    The code is simplier reading. Another good practice, in my opinion, is calling the getXXX() in toString() too (instead then this.XXX), beacuse the getXXX() can have an important logic.

    I think that use the name of attribute without this is'nt a good idea for the maintenance of the application.

提交回复
热议问题