New answers tagged


Checkout this post by Bob Buzzard, looks like both the operands must have the same type and the first one is the one to respect. He links to the Java documentation supporting this (haven't read the full thing myself).


Apex has a particular restriction that both paths of the ternary operator must be compatible types, and if using an assignment, must be compatible with the assignment. // Valid Decimal d = true? 5: 10.0; // Invalid Integer i = true? 5: 10.0; The first one is valid because the Integer 5 can be cast to a Decimal automatically, while the second is invalid, ...

Top 50 recent answers are included