groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-7436) Multiple inheritance of traits - conflict resolution
Date Mon, 06 Aug 2018 09:38:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7436?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16569947#comment-16569947
] 

Paul King edited comment on GROOVY-7436 at 8/6/18 9:37 AM:
-----------------------------------------------------------

The more Groovy idiomatic way to define X and Y in your second example would be to just remove
the {{implements A}} from traits B and C.
Alternatively, you can specify exactly where you want the implementation to come from:
{code}
class X implements A, B, C {
    String op2() { B.super.op2() }
}

class Y implements A, C, B {
    String op3() { C.super.op3() }
}

class Z implements B, C, A {
    String op2() { B.super.op2() }
    String op3() { C.super.op3() }
}
{code}


was (Author: paulk):
The more Groovy idiomatic ways to define X and Y in your second example would be to just remove
the implements A from traits B and C.
Alternatively, you can specify exactly where you want the implementation to come from:
{code}
class X implements A, B, C {
    String op2() { B.super.op2() }
}

class Y implements A, C, B {
    String op3() { C.super.op3() }
}

class Z implements B, C, A {
    String op2() { B.super.op2() }
    String op3() { C.super.op3() }
}
{code}

> Multiple inheritance of traits - conflict resolution
> ----------------------------------------------------
>
>                 Key: GROOVY-7436
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7436
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Thornton Chamberlain
>            Priority: Major
>
> {noformat}
> trait A {
>     String exec() {'A'}
> }
> trait B implements A {
>     String exec() {'B'}
> }
> trait C implements A {
> }
> class X implements A, B, C {}
> def x = new X()
> assert x.exec() == 'B'
> {noformat}
> An equivalent example in Scala will use the exec() implementation from B, as asserted.
 Groovy will take the implementation from the last declared trait, C, which inherits the implementation
from A but does not define its own implementation.  I think Groovy should use the implementation
from the last declared trait that defines its own implementation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message