Created
May 24, 2019 08:22
-
-
Save peter-lawrey/c9c64437a60e77148d7727fd2ac06872 to your computer and use it in GitHub Desktop.
If the Predicate is defined inside Never, this program never completes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please explain why this happen?