aboutsummaryrefslogtreecommitdiff
path: root/test/pretty/resource/after/Switch19.java
blob: 5947830bdb591868cd0cbd0a4caa6f2e44d8c8ce (plain)
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
public class Switch19 {
	String switchPatternMatching(Object o) {
		return switch (o) {
			case Integer i -> String.format("int %d", i);
			case Long l -> String.format("long %d", l);
			case Double d -> String.format("double %f", d);
			case String s -> String.format("String %s", s);
			default -> o.toString();
		};
	}

	String switchNull(Object o) {
		return switch (o) {
			case null, default -> "?";
		};
	}

	String switchGuardPattern(Object o) {
		return switch (o) {
			case String s when s.length() > 1 -> s;
			case String s -> s;
			default -> o.toString();
		};
	}

	String switchParenthesizedPattern(Object o) {
		return switch (o) {
			case (String s) -> s;
			default -> o.toString();
		};
	}
}