Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Last active April 19, 2020 08:23
Show Gist options
  • Save artem-smotrakov/eb018ebf2f321753eb71e5383bde5c7c to your computer and use it in GitHub Desktop.
Save artem-smotrakov/eb018ebf2f321753eb71e5383bde5c7c to your computer and use it in GitHub Desktop.
What do you think is going to happen here? Options: compilation error, runtime error, it prints "Oops", it prints "OopsOops", it prints "Forty-two".
public class StrangeYield {
public static void main(String[] args) {
go(0);
}
static void go(int n) {
System.out.println(
switch (n) {
case 42 -> "Fotry-two";
default -> {
yield("Oops");
}
}
);
}
static String yield(String s) {
return s + "Oops";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment