Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Wojtek Newsgroups: comp.lang.java.programmer Subject: Re: Assigning void Date: Sat, 13 Oct 2012 12:35:34 -0700 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: <793cfc49-67ae-4fcf-8176-d970eb88f895@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15"; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="02a139954f423f27040ed3cd2ab90b3b"; logging-data="4678"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eXebXa40knfHsERFmTwavyFru8mMCTWM=" X-Newsreader: MesNews/1.08.03.00-gb Cancel-Lock: sha1:bd0Jv+vhdehZ0rTlRul3BL6KtHY= Xref: csiph.com comp.lang.java.programmer:19291 Lew wrote : > Wojtek wrote: >> I can legally do the following: >> >> if (server.getConnectionType() == ConnectionType.ACTIVE) >> ftp.enterLocalActiveMode(); >> else >> ftp.enterLocalPassiveMode(); >> >> but I want to do: >> >> (server.getConnectionType() == ConnectionType.ACTIVE) ? >> ftp.enterLocalActiveMode() : ftp.enterLocalPassiveMode(); >> >> However the compiler insists that I must have an assignment even though >> both ftp methods return void. I would think that the compiler would be >> smart enough to realize that nothing CAN be returned. >> >> Oh yes, I am using Eclipse with Java 7 >> >> Thoughts? I mean other than stylistic comments... > > The compiler is smart enough to realize that nothing can be returned. > > It's also smart enough to realize that standalone expressions, such > as this one or a lone 'x', are not legal. > > http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.8 > and the rest of Chapter 14. I had not considered it to be an expression, though thinking about it now, it would have to be. But it is kind of special in that any assignment is conditional, so it could have special rules. -- Wojtek :-)