-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSwitchCase.java
30 lines (23 loc) · 883 Bytes
/
SwitchCase.java
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
package com.di1shuai.java19.switchcase;
import com.di1shuai.java19.recordcase.Point;
import java.util.ArrayList;
import java.util.Arrays;
public class SwitchCase {
public static void main(String[] args) {
typeTester(null);
typeTester("s");
typeTester(Color.RED);
typeTester(new Point(1, 2));
typeTester(Arrays.asList("1", 2, 0.1));
}
static void typeTester(Object o) {
switch (o) {
case null -> System.out.println("null");
case String s -> System.out.println("String");
case Color c -> System.out.println("Color: " + c.toString());
case Point p -> System.out.println("Record class: " + p.toString());
case int[] ia -> System.out.println("Array of ints of length" + ia.length);
default -> System.out.println("Something else");
}
}
}