[
https://issues.apache.org/jira/browse/GROOVY-7772?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15177138#comment-15177138
]
Jochen Theodorou edited comment on GROOVY-7772 at 3/3/16 4:21 AM:
------------------------------------------------------------------
I think I don't understand pattern number 3 actually... I would have thought
you are talking about something like this:{code:Java}
class X {
static foo(){}
}
def x = new X()
def m = x.&foo
m.call()
{code}but this does not fail, not dynamic compiled and not static compiled. The
meaning of x.&y() is in all cases always x.y(), be x a class, y a static method
or not and combinations of it. Which is why pattern 4 fails. What happens if we
see x.&y(args...) like a method taking X and args..., for which we curry (in
the Groovy sense) the first argument with x? In other words: x.&y becomes
{xarg, args... -> xarg.y(args)}.curry( x ), then all cases work like before,
because that is actually what we are doing (kind of). A more Java-like version
would be to have {xarg, args... -> if (y is static) X.y(args) else
xarg.y(args)}.curry( x ). Then all 4 cases would work.
was (Author: blackdrag):
I think I don't understand pattern number 3 actually... I would have thought
you are talking about something like this:{code:Java}
class X {
static foo(){}
}
def x = new X()
def m = x.&foo
m.call()
{code}but this does not fail, not dynamic compiled and not static compiled. The
meaning of x.&y() is in all cases always x.y(), be x a class, y a static method
or not and combinations of it. Which is why pattern 4 fails. What happens if we
see x.&y(args...) like a method taking X and args..., for which we curry (in
the Groovy sense) the first argument with x? In other words: x.&y becomes
{xarg, args... -> xarg.y(args)}.curry(x), then all cases work like before,
because that is actually what we are doing (kind of). A more Java-like version
would be to have {xarg, args... -> if (y is static) X.y(args) else
xarg.y(args)}.curry(x). Then all 4 cases would work.
> Class.&instanceMethod had better to have same meaning of
> Class::instanceMethod of Java8
> ---------------------------------------------------------------------------------------
>
> Key: GROOVY-7772
> URL: https://issues.apache.org/jira/browse/GROOVY-7772
> Project: Groovy
> Issue Type: Improvement
> Components: groovy-runtime
> Affects Versions: 2.4.6
> Reporter: UEHARA Junji
> Priority: Minor
>
> Groovy's operator .& for method is similar functionality to Java8's method
> reference operator ::.
> ||No.||lhs||rhs||meaing of Groovy's .& (Closure) ||meaning of java8's ::
> (FunctionalInterface)||
> |1|instance|instanceMethod| { ..args -> instance.instanceMethod(args) | same
> as groovy |
> |2|Class|staticMethod| { ..args -> Class.staticMethod(args) | same as groovy |
> |3|instance|staticMethod| ERROR groovy.lang.MissingMethodException: | Error
> same as groovy (compile error) |
> |4|Class|instanceMethod|error| Function<RetType,Class,Args..>, where method
> instance method of Class which is declared as ```RetType
> instanceMethod(Args..) {...}```. In other words it is interpreted as a
> function which takes LHS Class as the first parameter which additionally
> inserted to the method.)|
> IMHO, i'd like to propose to change the No 4 pattern semantics of groovy
> same as Java 8 's. Because:
> * You can write:
> {code}
> ["a,b,c"].collect ( String.&toUpperCase )
> {code}
> instaed of
> {code}
> ["a,b,c"].collect { it.toUpperCase() }
> {code}
> * Can have correspond operator to java8's ::. which is understandablea and
> needed for Java programmers.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)