※ 引述《Senkousha ( )》之銘言:
: 在 JLS 15.11.2:
: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.11.2
: 裡面有提到如 T.super.name 這樣的 expression,
: 在 eclipse.jdt.core.dom 裡面是當作 SuperFieldAccess 像這樣來處理:
: SuperFieldAccess:
: [ ClassName . ] super . Identifier
: 而 ClassName 是一個 Name,不是 Type。
: 我的問題是,手邊有一份 javacc 4.2 裡的(2006?)範例文法 Java1.5.jj,
: 裡面在 parse primary expression 的 prefix 時,出現了這樣的 case:
: ClassOrInterfaceType() "." "super" "." <IDENTIFIER>
: 其中的 ClassOrInterfaceType() 是個可以包含 type argument 的 Type:
: <IDENTIFIER> [ TypeArguments() ] ( "." <IDENTIFIER> [ TypeArguments() ] )*
: 建出的 parser 也的確接受了 B<int>.super.field 這樣的語法,
: 這讓我有點想不通的地方是以下兩點:
: 1. 就算 class B 是一個 parameterized type ,B<TypeArg> 跟 B 有可能
: 對 super field access 造成影響嗎?畢竟可以存取的 super field
: 好像都是 static 的?
為什麼可以存取的 field 只能是 static?!
super.field 與 this.field 都是 access instance field 的語意,而
ClassName.this.field 與 ClassName.super.field 中的 ClassName 是用來
修飾(qualify) this/super(這在 non-static nested class 裡用的到,用來明確
指出 this/super 指的是 nested class 或是 enclosing class)。
: 大家覺得是 eclipse.jdt.core.dom 那邊的作法比較有道理,
: 還是覺得 eclipse 的 parser 應該也要吃 Type 比較好呢?
應該是不能夠有 ClassName<Type>.super.field 這樣子的寫法,因為這會隱含
誤導的語意在裡頭(類似在 GenericType 的 static field 型態宣告使用 Type-
Parameter)。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.138.166