它看起來像在編譯器中未經檢查的情況。反編譯後,擴展類獲得一個空的構造函數。因爲這種情況在運行時不起作用,所以測試應該引起您的注意。
我不知道如何使用這個類;我試過我知道的方式:
abstract class AbstractClass {
String string
Integer integer
AbstractClass(String string, Integer integer) {
this.string = string
this.integer = integer
}
}
class ImplClass extends AbstractClass { }
// every constructor fails
abs1 = new ImplClass('a', 1)
abs2 = [string: 'b', integer: 2] as ImplClass
abs3 = new ImplClass(abs: 'c', a: 3)
abs4 = ImplClass [string:'d', integer:4]
他們都沒有在運行時工作,但編譯得很好;-)。這種情況更多的是編譯錯誤與運行時錯誤。也許填充JIRA?
另一方面,如果您需要繼承構造函數,則可以在擴展類中使用@groovy.transfom.InheritConstructors
。這樣你就可以不需要明確地調用super()
的構造函數。