JLS 5.6 classifies SwitchExpression and ConditionalExpression as constructs in numeric choice context (when all result expressions are numeric) The computation of result type, their polyness or not all are all similarly defined. Essentially a switch is multi-way-conditional.
As such there is enormous room for code sharing by hoisting contract and default behavior to a new interface type say INumericChoiceContext that both switch expressions and ternary operators implement.
Comparing org.eclipse.jdt.internal.compiler.ast.SwitchExpression.resolveType(BlockScope) and org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(BlockScope) it is possible for the latter to be as minimal as the former.
JLS 5.6 classifies
SwitchExpressionandConditionalExpressionas constructs in numeric choice context (when all result expressions are numeric) The computation of result type, their polyness or not all are all similarly defined. Essentially a switch is multi-way-conditional.As such there is enormous room for code sharing by hoisting contract and default behavior to a new interface type say
INumericChoiceContextthat both switch expressions and ternary operators implement.Comparing
org.eclipse.jdt.internal.compiler.ast.SwitchExpression.resolveType(BlockScope)andorg.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(BlockScope)it is possible for the latter to be as minimal as the former.