You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/08/21 22:04:00 UTC
[jira] [Comment Edited] (GROOVY-8760) can't instantiate a class
that inherits from base class marked with @MapConstructor
[ https://issues.apache.org/jira/browse/GROOVY-8760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16587851#comment-16587851 ]
Paul King edited comment on GROOVY-8760 at 8/21/18 10:03 PM:
-------------------------------------------------------------
um - its not quite idempotent - i think i mi=ust have a tried in a some order and broken it - this work
{code}
@MapConstructor (post = {id = SequenceGenerator.standard.next() })
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
{code}
however if i try this - this will fail
{code}
@MapConstructor (post = {id = SequenceGenerator.standard.next() })
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@MapConstructor (post = \{id = SequenceGenerator.standard.next() })
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
{code}
like this
{noformat}
A (will, id:1)
Caught: java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
at com.softwood.scripts.B.<init>(TestOfferingAttributeGroup.groovy)
at com.softwood.scripts.TestOfferingAttributeGroup.run(TestOfferingAttributeGroup.groovy:39)
{noformat}
and only define the map constructor on a child
{code}
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@MapConstructor (post = {id = SequenceGenerator.standard.next() })
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
{code}
will work - but if you create a constructor on the parent - your map constructor is auto disabled ( i wanted the map constructor and on both parent and child as i was using that to set this id field inherited from the parent)
from groovy implementation perspective if you have applied the @MapContructor on a parent - shouldnt it be idempotent on the child?
for now i'm just going have to check carefully and test it does what i expect/doesn't fail
Will
was (Author: woodmawa):
um - its not quite idempotent - i think i mi=ust have a tried in a some order and broken it - this work
@MapConstructor (post = \{id = SequenceGenerator.standard.next() })
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
however if i try this - this will fail
@MapConstructor (post = \{id = SequenceGenerator.standard.next() })
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@MapConstructor (post = \{id = SequenceGenerator.standard.next() })
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
like this
A (will, id:1)
Caught: java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
at com.softwood.scripts.B.<init>(TestOfferingAttributeGroup.groovy)
at com.softwood.scripts.TestOfferingAttributeGroup.run(TestOfferingAttributeGroup.groovy:39)
and only define the map constructor on a chil
class A {
long id
String name
Boolean isDead
Boolean died
A() {}
String toString() {
"A ($name, id:$id)"
}
}
@MapConstructor (post = \{id = SequenceGenerator.standard.next() })
@InheritConstructors
class B extends A {
String toString() {
"B ($name)"
}
}
will work - but if you create a constructor on the parent - your map constructor is auto disabled ( i wanted the map constructor and on both parent and child as i was using that to set this id field inherited from the parent)
from groovy implementation perspective if you have applied the @MapContructor on a parent - shouldnt it be idempotent on the child?
for now i'm just going have to check carefully and test it does what i expect/doesnt fail
Will
> can't instantiate a class that inherits from base class marked with @MapConstructor
> -----------------------------------------------------------------------------------
>
> Key: GROOVY-8760
> URL: https://issues.apache.org/jira/browse/GROOVY-8760
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.5.1
> Environment: intellij 2018.1.4, java jdk 8.0_172, groovy 2.5.1
> Reporter: William Woodman
> Priority: Major
> Labels: features
>
> basic inheritance where parent is tagged with @MapConstructor then child class cant be instantiated
> example as follows
>
> {code}
> @MapConstructor
> class A {
> String name
> A() {}
> String toString() {
> "A ($name)"
> }
> }
> class B extends A {
> String toString() {
> "B ($name)"
> }
> }
> def myA = new A(name:"will")
> println myA
> def myB = new B(name:"fred")
> println myB
> {code}
> run this and get a RT exception
> {noformat}
> A (will)
> Caught: java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
> java.lang.NoSuchMethodError: com.softwood.scripts.A: method <init>()V not found
> at com.softwood.scripts.B.<init>(TestOfferingAttributeGroup.groovy)
> at com.softwood.scripts.TestOfferingAttributeGroup.run(TestOfferingAttributeGroup.groovy:28)
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)