diff --git a/slides.md b/slides.md index 8b5e224..2bda406 100644 --- a/slides.md +++ b/slides.md @@ -124,6 +124,24 @@ --- +# yield + +```java +var value = switch (input) { + case "a" -> { + yield 1; + } + case "b" -> { + yield 2; + } + default -> { + yield 0; + } +}; +``` + +--- + # Records :video_camera: ```java @@ -165,7 +183,7 @@ --- -# Records: Constructor canĂ³nico +# Records: Constructor CanĂ³nico :building_construction: ```java public record Movie(String title, List cast) { diff --git a/snippets/Switches.java b/snippets/Switches.java index cc1e224..b172414 100644 --- a/snippets/Switches.java +++ b/snippets/Switches.java @@ -9,6 +9,21 @@ System.out.println(value); } + void method11(String input) { + var value = switch (input) { + case "a" -> { + yield 1; + } + case "b" -> { + yield 2; + } + default -> { + yield 0; + } + }; + System.out.println(value); + } + void method2(Object obj) { var result = switch (obj) { case Integer i -> String.format("int %d", i);