Java 7 specification: variable identifiers are names, but no field names? What for?

http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.2

The specification states:

When determining the meaning of a name (§6.5), the context in which that name is displayed, taking into account. The rules of § 6.5 distinguish between contexts where a name (see) a package (§6.5.3), a type (§6.5.5), a variable or value in an expression (§6.5.6), or a method (clause 6.5.7) should be indicated )

So, as I understand it, names can only indicate the above objects that do not contain fields.

This is similar to the statements made a little lower:

Not all identifiers in a program are part of the name. Identifiers are also used in the following situations:

  • ...

  • In field access expressions (§15.11), where the identifier occurs after "." token indicate the member of the object, which is the value of the expression or keyword super that appears before the ".". Marker

  • ...

So my question is: what is the reason for this difference between local variables and fields?

+4
source share
1 answer

An important part:

The rules of section 6.5 distinguish between contexts in which a name (see) a package (§6.5.3), a type (§6.5.5), a variable or value in an expression (§6.5.6) or a method (clause 6.5. 7).

A field reference is also a name in this context because it is a value in an expression. (§6.5.6)

, . 6.5.5, :

6.5.6.1.

, , , (§6.4.1) , . .

(§8.3), (§8.4), (§8.8), (§8.6) (§8.3.2.2).

[...]

6.5.6.2.

Q.Id, Q , .

[...]

Q - , T - Q:

T , .

(§6.6) T Id, .

[ ... .]

+3

Source: https://habr.com/ru/post/1541928/


All Articles