You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2019/09/27 22:21:00 UTC

[jira] [Commented] (GROOVY-9259) Implementing Groovy interface with default methods can cause compile issues.

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

Daniel Sun commented on GROOVY-9259:
------------------------------------

An interface with default methods is actually a trait for now.
What you are trying is: class GroovyClass implements trait GroovyInterface, which extends interface JavaInterface.

It should work IMO... Am I missing something?  [~paulk] 

> Implementing Groovy interface with default methods can cause compile issues.
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-9259
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9259
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0-beta-3
>            Reporter: covers1624
>            Priority: Minor
>
> Hello!
> Consider the following classes.
> {code:java|title=test/JavaInterface.java|borderStyle=solid}
> package test;
> public interface JavaInterface {
>     String doStuff();
> }
> {code}
> {code:java|title=test/GroovyInterface.groovy|borderStyle=solid}
> package test
> interface GroovyInterface extends JavaInterface {
>     default doOtherStuff() {
>         return 'doot'
>     }
> }
> {code}
> {code:java|title=test/GroovyClass.groovy|borderStyle=solid}
> package test
> class GroovyClass implements GroovyInterface {
>     @Override
>     String doStuff() {
>         return "otherDoot"
>     }
> }
> {code}
> This code compiles with an error:
> {noformat}
> test/GroovyClass.groovy: 4: Method 'doStuff' from class 'test.GroovyClass' does not override method from its superclass or interfaces but is annotated with @Override.
>  @ line 4, column 5.
>        @Override
>        ^
> {noformat}
> However, removing the default method insideĀ ~GroovyInterface~, OR, declaring ~GroovyClass~ to implement both ~GroovyInterface~ AND ~JavaInterface~ will make compilation succeed again.
> Apologies if this is some form of intended behavior, although I suspect it isn't due to the nature of this issue.
> Thank You for your time looking into this issue! also thanks for a fantastically flexible language!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)