PROPOSAL: Elvis operator (original) (raw)
Marek Kozieł develop4lasu at gmail.com
Sat Mar 21 08:14:15 PDT 2009
- Previous message: Fwd: PROPOSAL: Elvis operator
- Next message: PROPOSAL: Elvis operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
W dniu 21 marca 2009 16:00 użytkownik Olivier Chorier <lapsus63 at gmail.com> napisał:
Ok, what about : int value ?= object.getSubObject().getValue() : -1; Pros : - I think the compiler could easily retranscript it using - Much more readable Cons : - The potential problem is that the "interpretation" differs from an &= or += operator
It's ok for me, in this case.
But did you ever wander why NPE is so common? Isn't that because people do not want write so much if-s and declare so many one time used variables.
but ?: can give something nice: void f(Some some){ ( some.getOut ?: defOut ).write(...); ... }
while ?= would require to: void f(Some some){ OutputStream out ?= some.getOut : defOut; out.write(...); // Now we need worry for 'out' till end of function. ... }
-- Pozdrowionka. / Regards. Lasu aka Marek Kozieł
http://lasu2string.blogspot.com/
- Previous message: Fwd: PROPOSAL: Elvis operator
- Next message: PROPOSAL: Elvis operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]