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

ASF GitHub Bot commented on GROOVY-10060:
-----------------------------------------

eric-milles commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826873641

   Something is missing in the stub generator, because when I try to add a 
static method to a groovy interface, it states that the java implementer needs 
to implement the abstract method.
   
   Here is my `org.codehaus.groovy.classgen.InterfaceTest` that is updated to 
try out the Java interop if these new changes:
   ```groovy
   package org.codehaus.groovy.classgen
   
   import org.codehaus.groovy.control.CompilerConfiguration
   import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
   import org.junit.Test
   
   final class InterfaceTest {
   
       @Test
       void testJavaImplementsGroovyInterface() {
           def config = new CompilerConfiguration(
               targetDirectory: File.createTempDir(),
               jointCompilationOptions: [memStub: true]
           )
           def parentDir = File.createTempDir()
           try {
               new File(parentDir, 'test').mkdir()
   
               def a = new File(parentDir, 'test/GClass.groovy')
               a.write '''package test
                   class GClass {
                   }
               '''
               def b = new File(parentDir, 'test/GInterface.groovy')
               b.write '''package test
                   interface GInterface {
                       GClass[] getGC()
                       default String foo() { 'foo' + GInterface.this.bar() }
                       private String bar() { 'bar' }
   //                    static  String baz() { 'baz' }
                   }
               '''
               def c = new File(parentDir, 'test/JClass.java')
               c.write '''package test;
                   public class JClass implements GInterface {
                       public GClass[] getGC() {
                           return new GClass[0];
                       }
                       public String toString() {
                           return this.foo();
                       }
                   }
               '''
               def d = new File(parentDir, 'Main.groovy')
               d.write '''
                   def jc = new test.JClass()
                   assert jc.getGC().length == 0
                   assert jc.toString() == 'foobar'
   //                assert test.JClass.baz() == 'baz'
               '''
   
               def loader = new GroovyClassLoader(this.class.classLoader)
               def cu = new JavaAwareCompilationUnit(config, loader)
               cu.addSources(a, b, c, d)
               cu.compile()
   
               loader.loadClass('Main').main()
           } finally {
               config.targetDirectory.deleteDir()
               parentDir.deleteDir()
           }
       }
   }
   ```




> Support static & private interface methods
> ------------------------------------------
>
>                 Key: GROOVY-10060
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10060
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: Compiler
>            Reporter: Christopher Smith
>            Assignee: Paul King
>            Priority: Major
>
> Apologies if this is a dupe, but I went back as far as 6000, and GROOVY-8299 
> is the only relevant ticket I saw.
> Since Java 8, interfaces can carry static methods like classes. Groovy still 
> (as of 3.0.8) does not support adding static methods to interfaces.
> {code}
> The method 'java.lang.String dynamoTableNameForType(java.lang.String)' from 
> interface 'com.example.HasDynamo' must not be static. Only fields may be 
> static in an interface.
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to