Created
April 27, 2021 10:20
-
-
Save Toparvion/7fba100a5cb001e49255f1f70bb7a125 to your computer and use it in GitHub Desktop.
IDEA switch expression bug sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pro.toparvion.sample.yield; | |
public class Yield { | |
public static void main(String[] args) { | |
if (args.length < 2) { | |
System.out.println("Usage: yield <concat|find> operand1 operand2"); | |
return; | |
} | |
String operation = args[0].toLowerCase(); | |
String operand1 = args[1]; | |
String operand2 = args[2]; | |
String result = switch (operation) { | |
case "concat" -> { | |
System.out.println("Performing concatination..."); | |
yield (operand1 + operand2); // there is method 'yield' but it shouldn't be called | |
} | |
case "replace" -> { | |
System.out.println("Performing replacement..."); | |
yield operand1.replaceAll(operand2, ""); | |
} | |
default -> throw new UnsupportedOperationException(operation); | |
}; | |
System.out.printf("Applying '%s' to '%s' and '%s' yields '%s'.\n", operation, operand1, operand2, result); | |
Yield.yield(result); | |
} | |
private static void yield(String arg) { | |
// some important stuff with arg | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment