Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Assigning void Date: Sat, 13 Oct 2012 20:28:22 +0000 (UTC) Organization: UK Free Software Network Lines: 59 Message-ID: References: NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1350160102 3018 84.45.235.129 (13 Oct 2012 20:28:22 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sat, 13 Oct 2012 20:28:22 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.java.programmer:19303 On Sat, 13 Oct 2012 12:42:23 -0700, markspace wrote: > On 10/13/2012 12:28 PM, Wojtek wrote: > >> So questioning a design decision and trying to understand its rational >> is trolling? Really? > > > Yup, because there's no way anyone on this list could possibly answer > that question. You might try asking some of the language conferences or > at JavaOne. They might be able to tell you, or at least give you a > rational. > > All I can personally say, and I'm pretty sure all anyone here can say, > is "Java is easy to read" is a goal, and allowing inline conditional is > seen as detrimental to that goal. Maybe. There's a big difference: - a conditional expression can be assigned to a boolean variable or consumed by an "if (condition) ..." statement - but "( cond ? expr : expr)" is a triadic operator that demands a conditional expression as its first operand and returns a result. Since Java syntax requires that an expression's result must be consumed and not discarded, it follows that the triadic operator ( cond ? expr : expr) *MUST* (a) have all three operands supplied and (b) can only appear on the right hand side of an assignment statement or somewhere that will consume its result. For instance, this somewhat contrived example compiles and runs: public class Triadic { public static void main(String[] args) { StringBuilder sb = new StringBuilder();; if (args.length > 0) for (int i = 0; i < ( args[0].equals("four") ? 4 : 10); i++) sb.append("*"); m(args.length > 0 ? sb.toString() : "Args, what args?"); } public static void m(String s) { System.out.println(s); System.exit(0); } } showing that the triadic doesn't *have* to be the rhs of an assignment, though it usually will be used that way, as long as its result will be used and not discarded. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |