Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: A new small quiz question Date: Wed, 16 Aug 2017 08:30:57 -0400 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 16 Aug 2017 12:26:44 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="35551023f947087197aa6b1c652ca93b"; logging-data="6521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SCgKrAUFxJDBjYKITNu8C" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:B0aCLusCROECroPokaM0eC+y4dM= Xref: csiph.com comp.lang.java.programmer:37255 On 8/16/2017 7:25 AM, Stefan Ram wrote: > Can you predict (without trying it out) what the output > of the following program is? Yes. > public final class Main > { > private static int f( final int i ) > { java.lang.System.out.println( i ); return i; } > > public static void main( final java.lang.String[] args ) > { int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; > > x[ f( 0 )]= x[ f( 1 )]= x[ f( 2 )]; > > java.lang.System.out.println( x[ 0 ]); }} Unlike many of your other quizzes and curiosities, this one appears to have some pedagogic value. However, I'm sure the lesson could be conveyed with less obfuscation. Also, were I teaching Java I would follow the advice of JLS 15.7 and discourage students from employing this linguistic oddity. -- esosman@comcast-dot-net.invalid Twelve hundred fifty-three days to go.