[ https://issues.apache.org/jira/browse/GROOVY-11558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17921736#comment-17921736 ]
Wouter Peers commented on GROOVY-11558: --------------------------------------- [~emilles] Thank you for clarifying that being a feature of the language. I went back looking for this in the language spec and I guess the following is what I missed and what you are referring to… According to [https://groovy-lang.org/closures.html#_method_pointers:] {quote}In Groovy, you can obtain a closure from any method with the [method pointer operator|https://docs.groovy-lang.org/latest/html/documentation/core-operators.html#method-pointer-operator]. {quote} > Method reference treated as closure in method dispatch > ------------------------------------------------------ > > Key: GROOVY-11558 > URL: https://issues.apache.org/jira/browse/GROOVY-11558 > Project: Groovy > Issue Type: Bug > Components: Compiler, Static Type Checker > Affects Versions: 4.0.24 > Reporter: Wouter Peers > Assignee: Eric Milles > Priority: Major > Labels: closure, dispatch, overloading > > When passing a method reference to an overloaded method of which one of the > signatures accepts a functional interface. Groovy seems to treat the method > ref as a closure and dispatches to the wrong method signature. > Example: > {code:groovy} > @FunctionalInterface > interface PresenceAware { > boolean isPresent() > } > class Presence { > static boolean isPresent(Object o){ > o != null > } > static boolean isPresent(PresenceAware p){ > p.isPresent() > } > } > class StringWrapper implements PresenceAware{ > private final String s > StringWrapper(String s) { > this.s = s > } > @Override > boolean isPresent() { > return s!= null && !s.empty > } > } > assert !Presence.isPresent(null) > assert Presence.isPresent('') > assert !Presence.isPresent(new StringWrapper('')) > assert Presence.isPresent(Integer.&compare) > // => MissingMethodException (in Groovy v4.0.24) > assert Presence.isPresent(Integer.&valueOf) > // => MethodSelectionException (in Groovy v4.0.24) > {code} > This code runs fine in Groovy v2.4.7—as I would expect, the method references > passed in the last two statements are treated as an Object when dispatching > to Presence::isPresent mehtod. > In Groovy v4.0.24 however the method references seem to be (wrongfully) > treated as closures and are dispatched to Presence::isPresent(PresenceAware) > signature. -- This message was sent by Atlassian Jira (v8.20.10#820010)