Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.programmer Subject: Re: Multichar tokens Date: Mon, 15 Aug 2016 10:17:29 +0100 Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net GzKEHRfQJqUzBMk+GnRFDg874RjuXw5Ct9c57UA3uQE7S8GJtb Cancel-Lock: sha1:QbyTsVSkcw14iVgqTlt9xdabC3w= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:35348 On 13/08/16 23:05, Stefan Ram wrote: > In Java, »- -2« must be written as »- -2« and not as »--2«, > because there also is a special »--« operator. S Surely there is no ambiguity, --2 would be an illegal operation since you cannot decrement a constant. The Java lang. specification says: "The result of the unary [++/--]expression must be a variable of a type that is convertible (§5.1.8) to a numeric type, or a compile-time error occurs." Since 2 is not a variable it's a compile-time error: Test.java:6: error: ';' expected i = i --2; ^ Test.java:7: error: ';' expected i--2; ^ 2 errors Neither format of --2 is allowed. Are there any others? If you are worried about any potential ambiguity, remove it with parentheses. -(-2) has no ambiguity, and no reason to be misinterpreted. class Test { public static void main(String[] args) { int i = 3; i = i -(-2); System.out.println(i); } $ javac Test.java $ java Test 5