Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx07.iad.POSTED!not-for-mail From: Daniel Pitts User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Array initialization References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Lines: 21 Message-ID: X-Complaints-To: abuse@newsrazor.net NNTP-Posting-Date: Wed, 29 Jul 2015 20:52:54 UTC Date: Wed, 29 Jul 2015 13:52:54 -0700 X-Received-Bytes: 1432 X-Received-Body-CRC: 3112876649 Xref: csiph.com comp.lang.java.programmer:32198 On 7/28/15 11:06 PM, Stefan Ram wrote: > Recently, being away from the keyboard, I wondered whether > the following was legal in Java: > > public final class Main > { public static void main( final java.lang.String[] args ) > { int a[] ={ 0, a[ 0 ] + 1, a[ 1 ]+ 1 }; > java.lang.System.out.println( a[ 0 ]); > java.lang.System.out.println( a[ 1 ]); > java.lang.System.out.println( a[ 2 ]); }} > > Turned out, I got an error message: > > Main.java:3: error: variable a might not have been initialized > { int a[] ={ 0, a[ 0 ]+ 1, a[ 1 ]+ 1 }; > ^ > 1 error > Yep, that makes total sense. I wouldn't expect anything different.