Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
-2 votes
2 answers
69 views

Clarity on Java Lambda Syntax [duplicate]

From my understanding, this is a single statement in Java: while((x % p == 0l) && (x > p)) x /= p; If that is the case, why is this a syntax error: final AtomicLong subtotal = new ...
Tripp Kinetics's user avatar
0 votes
0 answers
70 views

How does the lambda work? How does it know to call the functional interface? I want details because nothing I've seen explains it well [duplicate]

This is in a javafx program and it runs. button.setOnAction(_ ->{ int side = 0; Random rand = new Random(); side = rand.nextInt(2); if(side == 0){ //code here else{ ...
Schuyler Bradshaw's user avatar
12 votes
1 answer
590 views

Ambiguity in method references

Consider the following snippet: public static void main(String[] args) { Function<String, String> function = String::toUpperCase; //OK // Comparator<String> ...
Rohan Jaiswal's user avatar
0 votes
2 answers
195 views

Predicates and functions

public static void main(String[] args) { List<String> strings = Arrays.asList("a", "b", "c", "d"); strings.stream() .filter(s -> ...
l a s's user avatar
  • 3,915
1 vote
0 answers
22 views

Why Optional lambda replace with method reference Causing NullPointerException [duplicate]

There is a A Class class A { private String str; public void setStr(String str) { this.str = str; } } this method works fine; public static void main(String[] args) { ...
周亿进's user avatar
1 vote
1 answer
54 views

How to break an iteration and modify parent with child value in a nested list using java streams

I have this scenario: public class A { private String aValue; private List<B> bList; } public class B { private List<C> cList; } public class C { private String cValue; } ...
R42t's user avatar
  • 11
-1 votes
2 answers
108 views

How to remove these braces around this lamda expression?

Sonarlint I use with IntelliJ sends me a warning S1602 "Remove useless curly braces around statement" on this statement : communes.foreachPartition( partition -> { partition....
Marc Le Bihan's user avatar
-3 votes
1 answer
59 views

Can I use a lambda expression to return a single value of a collections? [duplicate]

I have a Collection of and I want to make a simple filter to obtain a T value, for example an getById( int idOfT) I tried this: return (T) stream.filter( t -> t.getId().equals(id)); but it does'...
sevila's user avatar
  • 56
1 vote
3 answers
103 views

Is this a correct interpretation of what computeIfAbsent is doing in this code?

I am reading someone else's code which uses computeIfAbsent. I don't often use lambdas, and I want to be cautious as I try to understand what it's doing. Rewriting this for my own understanding, is ...
Zhro's user avatar
  • 2,635
0 votes
0 answers
43 views

Creation multimap throught lambda-expression

I am reading a book "Effective Java" and coming up with fragmnet of code: public enum Phase { SOLID, LIQUID, GAS; public enum Transition { MELT(SOLID, LIQUID), FREEZE(...
Александр Скворцов's user avatar
2 votes
2 answers
82 views

Compare two different java collection objects with a common attribute using java streams api

I have two Sets containing 2 different objects 1. Set<A> 2. Set<B> class A { private String id; private String name; private B objB; } class B { ...
sairajgemini's user avatar
1 vote
1 answer
43 views

Unexpect Behavior with Multiple Java Threads and TreeMap.put()

When running the following code: import java.util.Collections; import java.util.Map; import java.util.TreeMap; public final class ThreadTest { int N = 4; Map<Integer, Proxy> proxy = ...
mike_uvw's user avatar
0 votes
1 answer
37 views

Junit for Consumer class returning lambda

I am writing junit test case for below for consumer class which has below method. @Bean @Transactional public Consumer<Message<String>> response() { return message -> { ...
Kinjal R's user avatar
-1 votes
2 answers
76 views

lambda function uses member variable and produces different results

I dont know why the code runs without errors. From what I learned, in functional programming, same input results in same output and function's internal state cannot be changed from outside. When I ...
Deenadayalan's user avatar
0 votes
0 answers
34 views

Java lambdas/method references used as callbacks in addCallback/removeCallback style methods

I've read about this but I haven't found a clear answer. Assume an API like the following: Callback callback = new Callback(); myApi.addCallback(callback); [...] myApi.removeCallback(callback); Now, ...
user1831114's user avatar

15 30 50 per page
1
2 3 4 5
361