[問題] 一個 java expression 裡有兩個 this

看板java作者 (邀怪)時間16年前 (2009/03/27 21:52), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/4 (看更多)
請問一下, Java 的一個 expression 裡有機會出現一個以上的 this 或 super 嗎? 從 Java 的 Grammar 看起來似乎允許: Expression3 = Primary ( Selector )* ( PostfixOp )* | ... Primary = "this" [ arguments ] | "super" SuperSuffix | ... Selector = "." "this" | "." "super" SuperSuffix | ... 但我卻想不出哪種 expression 可以有多個 this 或 super 或混合使用的: this.toString(); // OK Foo.this.toString(); // OK this.this.toString(); // Syntax Error super.toString(); // OK Foo.super.toString(); // OK super.super.toString(); // Syntax Error this.super.toString(); // Syntax Error super.this.toString(); // Syntax Error super.Foo.this.toString(); // Syntax Error 是有什麼狀況我沒想到的嗎? 還是 Java Grammar 那樣寫只是為了簡單, 實際在語意處理的時候並不允許多個 this 或 super 出現在一個 expression 中? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.90.107

03/27 22:56, , 1F
compiler?
03/27 22:56, 1F

03/28 00:07, , 2F
"a grammar", not "the [one and only] grammar"
03/28 00:07, 2F

03/28 23:05, , 3F
我記得this 跟 super只有一層,多層是錯誤的寫法
03/28 23:05, 3F
文章代碼(AID): #19pDerj9 (java)
文章代碼(AID): #19pDerj9 (java)