MCPcopy Create free account
hub / github.com/bsideup/jabel / JabelExample

Class JabelExample

example/src/main/java/com/example/JabelExample.java:7–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import java.util.function.Function;
6
7public class JabelExample {
8
9 public static void main(String[] args) {
10 System.out.println(new JabelExample().run(args));
11 }
12
13 public String run(String[] args) {
14 // Switch Expressions
15 // https://openjdk.java.net/jeps/325
16 var result = switch (args.length) {
17 case 1 -> {
18 yield """
19 one...
20 yet pretty long!
21 """;
22 }
23 case 2, 3 -> "two or three";
24 default -> new JabelExample().new Inner().innerPublic();
25 };
26 return result;
27 }
28
29 // Project Coin: Allow @SafeVarargs on private methods
30 // https://bugs.openjdk.java.net/browse/JDK-7196160
31 @SafeVarargs
32 private String outerPrivate(List<String>... args) {
33 // Look, Ma! No explicit diamond parameter
34 var callable = new Callable<>() {
35
36 @Override
37 public String call() {
38 // Var in lambda parameter
39 Function<Object, String> function = (var prefix) -> {
40 // Pattern Matching in instanceof
41 // https://openjdk.java.net/jeps/305
42 if (prefix instanceof String s) {
43 return s + Integer.toString(0);
44 } else {
45 throw new IllegalArgumentException("Expected string!");
46 }
47 };
48 // Test indy strings
49 return function.apply("idk ");
50 }
51 };
52
53 var closeable = new AutoCloseable() {
54
55 @Override
56 public void close() {
57
58 }
59 };
60
61 // Project Coin: Allow final or effectively final variables to be used as resources in try-with-resources
62 // https://bugs.openjdk.java.net/browse/JDK-7196163
63 try (closeable) {
64 return callable.call();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected