Good day to everyone,
I have a question regarding the usage of the ? :
operator in the lambda expressions, especially in the switch statements. Could you kindly clarify, why the below code would not work and will be marked as Not a statement
switch (separatedTransaction[0]) {
case "u" -> processUpdate(Integer.parseInt(separatedTransaction[1]), Integer.parseInt(separatedTransaction[2]), separatedTransaction[3]);
case "o" -> processOrder(separatedTransaction[1], Integer.parseInt(separatedTransaction[2]));
case "q" -> separatedTransaction.length > 2 ? processQuery(Integer.parseInt(separatedTransaction[2])):processQuery(separatedTransaction[1]);
default -> System.out.println("Invalid transaction");
}
And the next one will.
switch (separatedTransaction[0]) {
case "u" -> processUpdate(Integer.parseInt(separatedTransaction[1]), Integer.parseInt(separatedTransaction[2]), separatedTransaction[3]);
case "o" -> processOrder(separatedTransaction[1], Integer.parseInt(separatedTransaction[2]));
case "q" -> {
if (separatedTransaction.length > 2) {
processQuery(Integer.parseInt(separatedTransaction[2]));
} else {
processQuery(separatedTransaction[1]);
}
}
default -> System.out.println("Invalid transaction");
}
Is there a way to use the ? :
operator in the lambda expressions at all?
If so, could you kindly provide some code examples.