Skip to content

Instantly share code, notes, and snippets.

@peter-lawrey
Created May 24, 2019 08:22
Show Gist options
  • Save peter-lawrey/c9c64437a60e77148d7727fd2ac06872 to your computer and use it in GitHub Desktop.
Save peter-lawrey/c9c64437a60e77148d7727fd2ac06872 to your computer and use it in GitHub Desktop.
If the Predicate is defined inside Never, this program never completes.
import java.util.List;
import java.util.function.Predicate;
public class Main {
static final Predicate<String> test = s -> s.length() > 6;
static class Never {
// static final Predicate<String> test = s -> s.length() > 6;
static final List<String> fruit = List.of(
"Apples", "Bananas", "Pears",
"Oranges", "Tomatoes", "Cucumber");
static final long longFruit = fruit.parallelStream()
.filter(test)
.count();
}
public static void main(String... args) {
System.out.println("longFruit: " + Never.longFruit);
}
}
@tivrfoa
Copy link

tivrfoa commented Dec 22, 2020

Could you please explain why this happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment