Využij poslední šanci přihlásit se na naši Java akademii a najdi si práci snů!
Přihlas se
00
dny
00
hod.
00
min.
switch (obj) { case Integer i -> System.out.println("Integer: " + i); case String s -> System.out.println("String: " + s); case null -> System.out.println("It's null!"); default -> System.out.println("Unknown type"); }
switch (obj) { case String s && s.length() > 5 -> System.out.println("Long string: " + s); case String s -> System.out.println("Short string: " + s); case Integer i && i > 10 -> System.out.println("Large integer: " + i); default -> System.out.println("Other"); }
switch (obj) { case String s -> System.out.println("Short string: " + s); case String s && s.length() > 5 -> System.out.println("Long string: " + s); case Integer i && i > 10 -> System.out.println("Large integer: " + i); default -> System.out.println("Other"); }
sealed interface Shape permits Circle, Rectangle {} final class Circle implements Shape { } final class Rectangle implements Shape { }
Shape shape = new Circle(); switch (shape) { case Circle c -> System.out.println("It's a circle"); case Rectangle r -> System.out.println("It's a rectangle"); }