看板 java 關於我們 聯絡資訊
剛剛在試一些東西, 才發現 Java 裡如果繼承的 parent class 是 non-static inner class 而且沒有 default constructor 時, 需要用一個奇怪的語法來呼叫 parent constructor: class A { class B { class C { public C(int i) {} } } } class D extends A.B.C { public D() { new A().new B().super(123); } } 這種語法用的人應該不多吧? 那個 super() 這樣寫真不直覺... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.91.42
PsMonkey:敢問這樣設計的需求是...? 03/06 15:53
macbuntu:我在寫 compiler, 純粹是要知道語言所有的黑暗角落 :P 03/06 16:04
PsMonkey:喔喔喔... 推一下 (y) 03/06 16:38
ickxlin:因為B,C都不是static,若是則可 new A.B.C() 03/06 17:19
macbuntu:不對喔... 如果 B,C 都是 static 要直接 super(123), 03/06 17:26
macbuntu:new A.B.C(123) 不是 constructor 呼叫, compile 不過的 03/06 17:28