Skip to main content
39 events
when toggle format what by license comment
Jun 10, 2024 at 5:29 comment added caduceus Just use errorprone.info/bugpattern/AmbiguousMethodReference
Jun 16, 2020 at 10:01 history edited CommunityBot
Commonmark migration
Feb 26, 2019 at 14:59 history edited Deduplicator
edited tags
Nov 24, 2018 at 15:12 comment added GlenPeterson @Caleth imagine a library you use has Bar.foo(x) that does one thing and later gets a method x.foo() that does something else (or vice-versa). Now all your client code using the method reference syntax breaks because it's ambiguous which you are referring to.
Nov 23, 2018 at 14:40 comment added Caleth I would list "not distinguishing between x -> Bar.foo(x) and x -> x.foo()" as a benefit of the method reference syntax, not a drawback
Nov 4, 2016 at 19:32 comment added JimmyJames I had not realized that you could refer to an instance method like it's a static method with the object as the first parameter. That kind turned me upside down for a moment to think that Java works like Python now. Well not quite but still, wow. As to your last comment, you know you can use :: against an instance right? Or are you only referring to the reference to a instance method on the class?
Nov 4, 2016 at 19:06 history edited GlenPeterson CC BY-SA 3.0
deleted 1 character in body
Nov 4, 2016 at 15:26 history edited GlenPeterson CC BY-SA 3.0
added 162 characters in body
Nov 12, 2015 at 21:55 answer added Roland Tepp timeline score: 0
Nov 11, 2015 at 13:16 vote accept GlenPeterson
Nov 11, 2015 at 10:54 answer added JasonMing timeline score: 20
Nov 10, 2015 at 23:37 comment added Sebastian Redl @GlenPeterson I know what you meant. I just don't think the difference is relevant if the method has a useful name.
Nov 10, 2015 at 14:07 comment added GlenPeterson @SebastianRedl I tried to clear it up by editing the question.
Nov 10, 2015 at 14:06 history edited GlenPeterson CC BY-SA 3.0
deleted 27 characters in body
Nov 10, 2015 at 13:53 history edited GlenPeterson CC BY-SA 3.0
deleted 66 characters in body
Nov 10, 2015 at 0:49 comment added Sebastian Redl "[...] a static one-argument method on the Accept class [or] a zero-argument instance method [...]?" How is that relevant?
Nov 9, 2015 at 15:13 history edited GlenPeterson CC BY-SA 3.0
added 239 characters in body
Sep 14, 2015 at 21:01 comment added Stuart Marks "The method reference syntax won't work on methods that take or return primitive arrays, throw checked exceptions...." That's not correct. You can use method references as well as lambda expressions for such cases, as long as the functional interface in question allows it.
Jul 21, 2015 at 15:15 comment added GlenPeterson @LukasEder Oops - thanks! I've fixed that error. I must have been testing with a method that expected a java.util.function.Function instead of a Consumer.
Jul 21, 2015 at 15:12 history edited GlenPeterson CC BY-SA 3.0
deleted 13 characters in body
Jul 21, 2015 at 7:53 comment added Lukas Eder "The method reference syntax won't work on methods that return void" - How so? I'm passing System.out::println to forEach() all the time...?
Jul 20, 2015 at 23:33 history edited GlenPeterson CC BY-SA 3.0
added 127 characters in body
May 29, 2015 at 18:47 answer added h.j.k. timeline score: 38
Apr 26, 2015 at 22:54 audit Close votes
Apr 26, 2015 at 22:54
Apr 17, 2015 at 0:12 audit Close votes
Apr 17, 2015 at 0:14
Apr 11, 2015 at 17:12 history edited Robert Harvey CC BY-SA 3.0
added 8 characters in body
Apr 1, 2015 at 12:37 comment added GlenPeterson @m3th0dman The question is based on the assumption that the lambda syntax is clearer and asks if there is a performance reason to use a method reference instead. Open-ended, opinion-based questions about "which is better" are not allowed on StackExchange. This question is specifically about performance. You are free to discuss other reasons to choose one syntax over the other in an answer, if you chose to do so, but I'm not asking that kind of question here.
Apr 1, 2015 at 7:53 comment added Random42 @GlenPeterson It's not clear; is the question about the best/most syntax between lambdas and method references or is it about which one provides more performance? If it's the first case I believe you need to update the title.
Mar 31, 2015 at 20:37 comment added Giorgio .map(_.acceptValue()): If I am not mistaken, this looks very much like the Scala syntax. Maybe you are just trying to use the wrong language.
Mar 31, 2015 at 20:35 history edited GlenPeterson CC BY-SA 3.0
added 206 characters in body
Mar 31, 2015 at 20:30 history edited GlenPeterson CC BY-SA 3.0
added 206 characters in body
Mar 31, 2015 at 20:26 comment added GlenPeterson @Snowman and Doval, This question isn't about whether first-class functions are good or bad. It's about choosing the best Java 8 syntax to express them in. I've updated the question and added examples.
Mar 31, 2015 at 20:10 history edited GlenPeterson CC BY-SA 3.0
added 603 characters in body
Mar 27, 2015 at 10:17 history tweeted twitter.com/#!/StackProgrammer/status/581399620368093184
Mar 26, 2015 at 15:48 comment added user22815 @Doval I have used lambdas as method-level adapters before. In those cases I did need an anonymous chaperone so users of the lambda did not need to know about the underlying implementation. However, I do agree that in other cases it might be overkill.
Mar 26, 2015 at 15:41 comment added Doval I think you're worrying about performance prematurely. In my opinion performance should be a secondary consideration for using a method reference; it's all about expressing your intent. If you need to pass a function somewhere, why not just pass the function instead of some other function that delegates to it? It seems strange to me; like you don't quite buy that functions are first-class things, they need an anonymous chaperone to move them around. But to address your question more directly, I wouldn't be surprised if a method reference can be implemented as a static call.
Mar 26, 2015 at 15:27 history edited GlenPeterson CC BY-SA 3.0
edited tags; edited title
Mar 26, 2015 at 15:19 comment added user22815 This does not answer your question, but there are other reasons for using closures. In my opinion, many of them far outweigh the tiny overhead of an additional function call.
Mar 26, 2015 at 15:16 history asked GlenPeterson CC BY-SA 3.0