[
https://issues.apache.org/jira/browse/GROOVY-11439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17865248#comment-17865248
]
Eric Milles edited comment on GROOVY-11439 at 7/11/24 11:18 PM:
----------------------------------------------------------------
A closure or lambda is acting as the interface implementation in this case. It
works best when you supply a closure with no arrow, which lets it vary for the
different method signatures of the interface.
was (Author: emilles):
A closure or lambda is acting as the interface implementation in this case. It
is meant for an interface with one abstract method.
> closure is assignable to java.io.InputStream
> --------------------------------------------
>
> Key: GROOVY-11439
> URL: https://issues.apache.org/jira/browse/GROOVY-11439
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Priority: Minor
> Labels: groovy
>
> I am not sure if this is an expected behavior or not, but a lambda expression
> is assignable to java.io.InputStream
>
> {code:java}
> class Test {
> public static void main(String[] args) {
> java.io.InputStream x = (int p, int p2) -> p;
> System.out.println(x.read());
> }
> } {code}
> h3. Actual behavior
> The code compiles, but I get the following exception at runtime
> {code:java}
> Exception in thread "main" groovy.lang.MissingMethodException: No signature
> of method: Test$_main_closure1.doCall() is applicable for argument types: ()
> values: []
> Possible solutions: doCall(int, int), isCase(java.lang.Object),
> isCase(java.lang.Object), findAll(), findAll(), findAll(groovy.lang.Closure)
> at
> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:259)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1006)
> at groovy.lang.Closure.call(Closure.java:452)
> at InputStream1_groovyProxy.read(Unknown Source)
> at Test.main(test.groovy:4) {code}
> h3. Expected behavior
> The code should have been rejected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)