File: LambdaBreakpoints1.java

package info (click to toggle)
eclipse-jdt-debug 4.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,876 kB
  • sloc: java: 234,390; xml: 6,367; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 979 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class LambdaBreakpoints1 {
	public static void main(String[] args) throws Exception {
		ExecutorService executor = Executors.newSingleThreadExecutor();
		StringBuilder s = new StringBuilder();
		CompletableFuture<?> f = CompletableFuture.completedFuture("0");
		f = f.thenApply((x) -> {
			s.append(x).append("1");
			return s.toString(); // breakpoint 1
		})
		.thenApply(x ->
			s.append("2") // breakpoint 2
		)
		.thenRun(() -> lastCall(s))
		.thenRunAsync(() -> {}, executor);
		executor.shutdown();
		f.get();
		String result = s.toString();
		System.out.println(result); // breakpoint 4
	}

	private static void lastCall(StringBuilder b) {
		b.append(C.s());
	}

	static class C {
		static String s() {
			if (Boolean.valueOf("true")) // breakpoint 3
				return "3"; // <--- breakpoint 3 should not be here
			return "???";
		}
	}
}