PROPOSAL: Elvis operator (original) (raw)
Jeremy Manson jeremy.manson at gmail.com
Sat Mar 21 12:41:11 PDT 2009
- Previous message: PROPOSAL: Elvis operator
- Next message: PROPOSAL: Elvis operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Mar 21, 2009 at 7:23 AM, Marek Kozieł <develop4lasu at gmail.com> wrote:
2009/3/21 Olivier Chorier <lapsus63 at gmail.com>
I initially thought it was a good idea, but after a bit reflection, I don't think it is a real 'plus' compared with the ternary operator.
For example, how would you simplify those lines of code (assuming the coder loves ternary operator) : int value = object == null ? -1 : (object.getSubObject() == null ? -1 : (object.getSubObject().getValue() == null ? -1 : object.getSubObject().getValue())); Does somebody has an idea (excepting using an ugly try-catch statement) to write this much clearer ? (sorry for code indentation)
2009/3/21 Stephen Colebourne <scolebourne at joda.org>
You wrong, this should look like: int value = object.?getSubObject().?getValue() ?: -1
It is worth pointing out that after strenuous objection, Stephen took .? out of this proposal.
Jeremy
- Previous message: PROPOSAL: Elvis operator
- Next message: PROPOSAL: Elvis operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]