[
https://issues.apache.org/jira/browse/GROOVY-10504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17497042#comment-17497042
]
Eric Milles edited comment on GROOVY-10504 at 2/23/22, 9:34 PM:
----------------------------------------------------------------
This does indeed work in Groovy 3, but leads to ambiguous/non-deterministic
behavior if your class implements multiple interfaces (see GROOVY-8164).
Groovy 4 conforms to Java interface requirements in this situation. You must
use a qualifier for the static method call. So "JavaInterface.getString('OK')"
in this case.
was (Author: emilles):
This does indeed work in Groovy 3, but leads to ambiguous/non-deterministic
behavior if your class implements multiple interfaces (see GROOVY-8164).
Groovy 4 now conforms to Java interface requirements in this situation. You
must use a qualifier for the static method call. So
"JavaInterface.getString('OK')" in this case.
> Cannot call static method from Java interface (Groovy 4)
> --------------------------------------------------------
>
> Key: GROOVY-10504
> URL: https://issues.apache.org/jira/browse/GROOVY-10504
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.0
> Reporter: Renato Athaydes
> Assignee: Eric Milles
> Priority: Major
>
> Create a Java interface with a static method:
> {code:java}
> public interface JavaInterface {
> static String getString(String input) {
> return input;
> }
> }
> {code}
>
> A simple Groovy class that uses that:
>
> {code:java}
> class Example implements JavaInterface {
> static void main(String[] args) {
> println getString('OK')
> }
> }
> {code}
> Running this works fine in Groovy 3.0.9.
> In Groovy 4.0.0 I get this runtime error:
> {noformat}
> Exception in thread "main" groovy.lang.MissingMethodException: No signature
> of method: static tests.Example.getString() is applicable for argument types:
> (String) values: [OK]
> Possible solutions: toString(), toString(), getAt(java.lang.String)
> at
> groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1677)
> at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1663)
> at
> org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.callStatic(StaticMetaClassSite.java:64)
> at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:54)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:231)
> at tests.Example.main(Example.groovy:5)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)