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/06 09:38:00 UTC

[jira] [Commented] (GROOVY-7436) Multiple inheritance of traits - conflict resolution

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

Paul King commented on GROOVY-7436:
-----------------------------------

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)