The "must return a value" is applicable only when the expression evaluation is completed normally. In case of an exception, the expression does not complete normally.
It is like saying a method whose return type is String must return a String. But the following method will compile even though it does not return a String:
String m(){
if(true) throw new RuntimeException();
}
But your point is valid, the option should mention this possibility to be correct. Will update.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
No, a switch expression cannot return void. It is not an expression in that case, it is a switch statement. Please go through the detailed explanation provided at the bottom of the question. It explains the difference between a switch statement and a switch expression.
If you like our products and services, please help us by posting your review here.