Skip to main content

All Questions

0 votes
1 answer
312 views

How to generate lazy stream from a fixed number of expressions in Java?

I would like to get the same as Stream.of, but lazy. I.e. I want to do the same as Stream<MyClass> s = Stream.of( expression1(), expression2(), expression3(), ... ) I can do List<...
Dims's user avatar
  • 51.4k
4 votes
1 answer
3k views

Why does the `orElseThrow()` method in Java take a `Supplier` as a parameter instead of an `Exception`?

Why does the orElseThrow() method in Java take a Supplier as a parameter instead of an Exception? This is the question and the best answer I have found is in here, stating The overarching concept ...
Aria's user avatar
  • 256
2 votes
1 answer
167 views

Method reference not evaluated lazily? [duplicate]

I was under the impression that the following lambda expression () -> object.method() was equivalent to the method reference object::method This is compounded by IntelliJ which keeps nagging me ...
Urs Beeli's user avatar
  • 825
13 votes
1 answer
508 views

Filter Function Not Lazy

I'm making my very own version of Java's Stream library for fun. Here's my class signature: class Stream<T> { Supplier<T> head; Supplier<Stream<T>> tail; ... } Also, I ...
Mohideen Imran Khan's user avatar
28 votes
6 answers
12k views

Lazy evaluation for logging in Java 8

When you have values than are expensive to compute, a common pattern you see in logging frameworks is if (log.isDebugEnabled()) { String value = expensiveComputation(); log.debug("value: {}", ...
David Ehrmann's user avatar
5 votes
2 answers
955 views

simulate Lazy in Java8

I wrote the following code to simulate Lazy<T> in Java: import java.util.function.Supplier; public class Main { @FunctionalInterface interface Lazy<T> extends Supplier<T> {...
shaked sapir's user avatar
8 votes
0 answers
3k views

Java Lambdas and Streams: pass streams around [closed]

I have a fairly dumb question. We all know that stream can have a number of intermediate operations but the real computation is done only when we call some terminal operation. Is it common to pass ...
Vadim Kirilchuk's user avatar
5 votes
2 answers
2k views

Java Lambda Iteration List from JPA [duplicate]

I found some strange behaviour when using lambda with JPA, seems java 8 lambda don't iterate when get a list from another object. For Example: List<MyObject> list = anotherObject....
DarkZaioN's user avatar