2016-05-19 43 views
1

两个类生成:Groovy的AST @Canonical:构造函数不是祖先的领域

家长

@Canonical 
class Parent { 
    int id 
} 

儿童

@Canonical 
class Child extends Parent { 
    String name 
} 

当从Java中使用,孩子只有默认和Child(字符串名称)构造函数(和Map,肯定),但没有Child(int id)和Child(int ID,字符串名称)构造函数。

AST有没有机会获得?

回答

3

您还需要在Child类上使用@InheritConstructors注释来引入预期的构造函数。

@Canonical @InheritConstructors 
class Child extends Parent { 
    String name 
} 
+0

确认...可悲的是,这种方法在使用'@ Canonical'注释时不起作用,因为构造函数是在事实之后生成的。不知道我是否应该删除这个答案或让它作为一个相关的例子。 – cjstehno