In Java, how can a name become a member of a Primary expression? [closed]

First, let’s take a look at a very simple piece of code.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class S { int x = 0; }
class Test1 {
public static void main(String[] args) {
S s = new S();
System.out.println("s.x=" + s.x);
}
}
</code>
<code>class S { int x = 0; } class Test1 { public static void main(String[] args) { S s = new S(); System.out.println("s.x=" + s.x); } } </code>
class S { int x = 0; } 
class Test1 { 
    public static void main(String[] args) {
        S s = new S(); 
        System.out.println("s.x=" + s.x);
    } 
}

s.x is a field access expression.

The following is the relevant syntax excerpted by me from the Java Language Specification:

15.11:

FieldAccess:

Primary . Identifier

super . Identifier

TypeName . super. Identifier

15.8: Primary:

PrimaryNoNewArray

ArrayCreationExpression

PrimaryNoNewArray:

Literal

ClassLiteral

this TypeName . this

( Expression )

ClassInstanceCreationExpression

FieldAccess

ArrayAccess

MethodInvocation

MethodReference

If only looking at the syntax excerpted above, then s.x seemingly does not conform to the syntax.The reason is that s seemingly does not belong to any member of the Primary expressions.

Fortunately, the specification gives an explanation later, and this is exactly where my doubt lies:

This part of the grammar of the Java programming language is unusual,
in two ways. First, one might expect simple names, such as names of
local variables and method parameters, to be primary expressions. For
technical reasons, names are grouped together with primary expressions
a little later when postfix expressions are introduced (§15.14).

names are grouped together with primary expressions a little later when postfix expressions are introduced”,My understanding of this sentence is that a name will become a member of the primary expressions under certain circumstances.

15.14:

Postfix expressions include uses of the postfix ++ and — operators.
Names are not considered to be primary expressions (§15.8), but are
handled separately in the grammar to avoid certain ambiguities. They
become interchangeable only here, at the level of precedence of
postfix expressions.

My question is:
1.Is my above understanding correct?

2.”They become interchangeable only here, at the level of precedence of
postfix expressions
“,
(1).What does this sentence mean?
(2).Can you explain, based on my example, why s in s.x becomes a member of the primary expressions here?(On the premise that my understanding is correct.)
(3).What is the relationship between this and the level of precedence of postfix expressions?
(4).What does “interchangeable” refer to?

Thank you for your reading.

8

s.x is not a primary expression, and does not “become a member of the primary expressions” at any point. s.x is parsed as an ExpressionName:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ExpressionName:
Identifier
AmbiguousName . Identifier
AmbiguousName:
Identifier
AmbiguousName . Identifier
</code>
<code>ExpressionName: Identifier AmbiguousName . Identifier AmbiguousName: Identifier AmbiguousName . Identifier </code>
ExpressionName:
  Identifier
  AmbiguousName . Identifier

AmbiguousName:
  Identifier
  AmbiguousName . Identifier

which is one of the options for a PostfixExpression, alongside Primary:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>PostfixExpression:
Primary
ExpressionName
PostIncrementExpression
PostDecrementExpression
</code>
<code>PostfixExpression: Primary ExpressionName PostIncrementExpression PostDecrementExpression </code>
PostfixExpression:
  Primary
  ExpressionName
  PostIncrementExpression
  PostDecrementExpression 

When the JLS says that names and primary expressions “become interchangeable” at the level of precedence of postfix expressions, it means that both names and primary expressions can be parsed as postfix expressions. It does not mean that names become primary expressions.

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật