All Questions
19 questions
2
votes
2
answers
240
views
Why does a Java lambda need to explicitly mention the method of the functional interface?
import java.util.function.Function;
public interface Printable {
public String print(String s);
public static void main(String[] args) {
Function<String, String> fn = p -> p +...
1
vote
3
answers
176
views
Ensuring run-once behavior in a multi-threaded environment via volatile lambdas?
I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor:
class ControllerImpl {
//...
boolean applyStrat(StratParam param) {
getStrat().apply(...
1
vote
2
answers
590
views
How do the SOLID principles apply in the context of Lambdas and Streams? [duplicate]
How are these principles applied in the context of streams and lambda expressions? In particular, the applicability with respect to the following three principles: - Single Responsibility Principle (...
3
votes
2
answers
254
views
Explicit type and final in stream lambdas
This argument has been going on for weeks:
Bot.getGuild().getMembers().stream()
.filter((final Member m) -> m.getRoles().size() == 0)
.filter((final Member m) -> !m.getUser()....
0
votes
2
answers
105
views
Make lambdas concise using enumerations?
Generally, we are looking to create a logging framework that can target human readable output as well as various structured data formats. So, a goal is minimizing code duplication in packaging the ...
1
vote
1
answer
488
views
Using lambdas to simulate python generators in java
I am currently dealing with an app that has several classes which are used to compare files in various formats (xls, csv, xml, html, pdf...). They are all implementing an interface that is defined ...
56
votes
6
answers
22k
views
Is using Lambda expressions whenever possible in java good practice?
I have recently mastered the Lambda expression that was introduced in java 8. I find that whenever I am using a functional interface, I tend to always use a Lambda expression instead of creating a ...
13
votes
3
answers
4k
views
In Java 8, is it stylistically better to use method reference expressions or methods returning an implementation of the functional interface?
Java 8 added the concept of functional interfaces, as well as numerous new methods that are designed to take functional interfaces. Instances of these interfaces can be succinctly created using ...
8
votes
0
answers
822
views
What lambda function optimizations, if any, are planned for Java 9 and beyond? [closed]
I'm working on a high-performance project where Java 8's lambda functions are enormously useful. I've found, however, that they're memory inefficient when used en masse. For example, suppose I need to ...
0
votes
1
answer
85
views
How confusing is `new SomeCollection(values...)::contains` as a Predicate? [closed]
Traditionally, a function that want to skip certain items during processing will accept a Collection or var-args argument, but in the Java 8 world I think I should switch to Predicates.
Now, since ...
2
votes
2
answers
3k
views
Java - Using a Function variable to set the toString() method's return value
Lately I've started adding this to certain classes in an in-house API:
public class MyClass {
// I usually do this with classes I expect to
// be printed out or tested a lot (particularly
// ...
50
votes
4
answers
22k
views
Why should I use "functional operations" instead of a for loop?
for (Canvas canvas : list) {
}
NetBeans suggests me to use "functional operations":
list.stream().forEach((canvas) -> {
});
But why is this preferred? If anything, it is harder to read and ...
14
votes
1
answer
7k
views
Java 8: Good practice to pass Streams around in APIs for lazy operations?
In pre-Java 8 lambda-heavy libraries like Guava, the outputs use common Java Collection Framework interfaces so is easy to pass them around to external/internal APIs and still harness some lazy ...
71
votes
3
answers
34k
views
Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?
Do method references skip the overhead of the lambda wrapper? Might they in the future?
According to the Java Tutorial on Method References:
Sometimes... a lambda expression does nothing but call an ...
0
votes
2
answers
2k
views
Handling multiple packet types in Java 8
I have a Netty-based game server implementation that handles 40 or so distinct packets with their own serialization structure, for brevity I'll refer to them as FooPacket, BarPacket, ... These packet ...