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

前端 未结 16 2199
广开言路
广开言路 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-20 11:55

    "this" prevents confusion with instance variables with the same name in the parent class/es.

    It's pretty much the complement to prepending with "super".

提交回复
热议问题