You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by daniel_sun <re...@hotmail.com> on 2016/10/19 12:12:14 UTC
答复: Lambda expression for Groovy 3
Hi Rémi,
Groovy can choose the right method to call :)
assert ['1', '2', '3'] == [1, 2, 3].collect(Integer.&toString)
Cheers,
Daniel.Sun
________________________________
发件人: Remi Forax [via Groovy] <ml...@n5.nabble.com>
发送时间: 2016年10月19日 19:29
收件人: daniel_sun
主题: Re: Lambda expression for Groovy 3
Daniel,
you have also to test that Type::method work not only with static methods but also with instance method.
The awful case being when you have a static method that takes an instance in parameter that 'overload' an instance method, like Integer.toString() and Integer.toString(int).
Rémi
----- Mail original -----
> De: "daniel_sun" <[hidden email]</user/SendEmail.jtp?type=node&node=5736203&i=0>>
> à: [hidden email]</user/SendEmail.jtp?type=node&node=5736203&i=1>
> Envoyé: Mercredi 19 Octobre 2016 12:23:09
> Objet: Re: Lambda expression for Groovy 3
> Hi Jochen,
>
> I plan to map Java's *::* to Groovy's *.&*, the following code is ok
> now. What do you think about it?
>
> [1, 2, 3].stream().forEach(System.out.&println) // object method,
> [1, 2, 3].stream().forEach(System.out::println)
> [1, 2, 3].stream().forEach(Objects.&requireNonNull) // class method, [1, 2,
> 3].stream().forEach(Objects::requireNonNull)
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context:
> http://groovy.329449.n5.nabble.com/Lambda-expression-for-Groovy-3-tp5736169p5736195.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
________________________________
If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/Lambda-expression-for-Groovy-3-tp5736169p5736203.html
To unsubscribe from Lambda expression for Groovy 3, click here<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5736169&code=cmVhbGJsdWVzdW5AaG90bWFpbC5jb218NTczNjE2OXwxMTQ2MjE4MjI1>.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
View this message in context: http://groovy.329449.n5.nabble.com/Lambda-expression-for-Groovy-3-tp5736169p5736204.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: 答复: Lambda expression for Groovy 3
Posted by Jochen Theodorou <bl...@gmx.org>.
On 19.10.2016 14:12, daniel_sun wrote:
> Hi R�mi,
>
> Groovy can choose the right method to call :)
>
> assert ['1', '2', '3'] == [1, 2, 3].collect(Integer.&toString)
I am sure that works only because the static Integer.toString(int) and
the virtual Integer.toString() return the same values. If you look at
> class X {
> def foo() {1}
> static foo(X x) {2}
> }
Then for a X.&foo covering virtual and static methods, there is no way
of knowing if we want to call the virtual foo or the static foo method.
Both would take and instance of X as argument.
bye Jochen