Why must I use the “this” keyword for forward references?

后端 未结 5 2062
孤街浪徒
孤街浪徒 2020-12-24 05:11

When I use the this keyword for accessing a non-static variable in a class, Java doesn\'t give any error. But when I don\'t use it, Java gives an error. Why mus

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 05:25

    Please look at the Java Language Specification: https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3

    This is the reason, IMO: The usage is via a simple name.

    So in this case you have to specify the name using this.

提交回复
热议问题