groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject @MapConstructor(includeSuperProperties = true) => java.lang.NoSuchMethodError ?
Date Sat, 05 May 2018 18:09:14 GMT
Why does @MapConstructor(includeSuperProperties = true) in the code 
below throw e.g. java.lang.NoSuchMethodError: groovy.A2: method 
<init>()V not found ?
Giving @MapConstructor(pre={super(args)}) seems to be doing what I want, 
i.e. also initialize the super classes...
(It is great that @MapConstructor supports final class members btw)

class GroovyMapConstructorSpike {
   @Test @Ignore @CompileStatic void mapConstructorTest() {
final a0 =new A0([x0:11,s0:"aa"])
     final a1 =new A1([x0:111,s0:"aaa",x1:222,s1:"bbb"])
     final a2 =new A2([x0:111,s0:"aaa",x1:222,s1:"bbb",x2:3333,s2:"cccc"])
     final a3 =new A3([x0:111,s0:"aaa",x1:222,s1:"bbb",x2:3333,s2:"cccc",x3:44444,s3:"ddddd"])
     println"a0=$a0" println"a1=$a1" println"a2=$a2" println"a3=$a3" }
}

@MapConstructor @ToString class A0 {
   final int x0 final Strings0 }

@MapConstructor(pre={super(args)})@ToString(includeSuper =true)class A1extends A0 {
   final int x1 final Strings1 }

@MapConstructor(pre={super(args)})@ToString(includeSuper =true)class A2extends A1 {
   final int x2 final Strings2 }

//@MapConstructor(includeSuperProperties = true) @ToString(includeSuper 
= true) class A3 extends A2 { // java.lang.NoSuchMethodError: groovy.A2: 
method <init>()V not found //@MapConstructor(includeSuperFields = true) 
@ToString(includeSuper = true) class A3 extends A2 { // 
java.lang.NoSuchMethodError: groovy.A2: method <init>()V not found 
@MapConstructor(pre={super(args)})@ToString(includeSuper =true)class A3extends A2 {// works
final int x3 final Strings3 }


Result:

a0=groovy.A0(11, aa)
a1=groovy.A1(222, bbb, groovy.A0(111, aaa))
a2=groovy.A2(3333, cccc, groovy.A1(222, bbb, groovy.A0(111, aaa)))
a3=groovy.A3(44444, ddddd, groovy.A2(3333, cccc, groovy.A1(222, bbb, 
groovy.A0(111, aaa))))

Cheers,
mg




Mime
View raw message