Puzzling Java statement of the day

Some days ago I stumbled across a Java statement which I thought was trivial at first, only to discover that I had no idea. I have a reasonable understanding of what a JVM does and how Java bytecode is executed. But as this example shows once again, that doesn’t necessarily spread to the Java programming language. The snippet below should explain my point.

int lorem = 1, ipsum = 2, dolor = 3;
if (lorem == (lorem = ipsum))
	f();
if ((ipsum = dolor) == ipsum)
	g();

Which of the above two methods f() and g() is actually invoked? Can you tell without compiling the code? Possible answers are:

  • None of the two methods get invoked, both call-sites are dead code.
  • Just f() is invoked and the call-site of g() is dead code.
  • Just g() is invoked and the call-site of f() is dead code.
  • Both methods are invoked, the conditions are pointless.

Ironically, I finally understood what was going on after looking at the generated bytecode (good old javap is your friend). I am not posting the disassembled code because that would spoil the fun. But once you look at it, the answer appears to be quite obvious.

Excellent blog you have got

Excellent blog you have got here.. It's difficult to find quality writing like yours nowadays.
I seriously appreciate people like you! Take care!!
http://Hidden-Canyon.1103110.N5.Nabble.com/The-Top-10-Sports-Jerseys-Of-... http://www.marbiko.pl/id-3026681065 http://www.veedelplus.de/remember-forever-the-big-game-for-2011-nba-all-...

Eclipse spoiled the fun for

Eclipse spoiled the fun for me, since it highlights comparisons between equal expressions (since Galileo I believe), and yes, the Eclipse code analyser gets this right. My first guess when reading the post was right, but I wouldn't have put money on it.

Here's the relevant JLS section: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#1...

This is very interesting, You

This is very interesting, You are an overly professional blogger.

I've joined your feed and look forward to looking for extra of your fantastic post.

Also, I have shared your site in my social networks https://drive.google.com/file/d/1NVBYp0U3wLMC6OaClx-xepDpovSF5EOk/view?u... https://drive.google.com/file/d/17gejt5c2F9A7pU3yd_TSN7bcuCVoc6jz/view?u... https://drive.google.com/file/d/14M2u-aHM-s60z3avec1TZMor6tYNFzp6/view?u...

An outstanding share! I've

An outstanding share! I've just forwarded this onto a coworker who was doing a little homework on this.
And he actually ordered me breakfast simply because I
discovered it for him... lol. So allow me to reword this....
Thanks for the meal!! But yeah, thanx for spending
some time to talk about this matter here on your web page.
http://aandetoys.com/2016/05/4u3ob43bsb17.html http://www.ddcarton.com/buying-an-additional-soccer-jerseys-as-a-variety... https://cobe.vn/types-of-basketball-jerseys.html

Hello, its pleasant paragraph

I was recommended this web

I was recommended this web site via my cousin. I am now not certain whether or
not this publish is written by means of him as no one
else understand such targeted approximately my problem.
You are incredible! Thanks! http://www.planetadamusica.com/indicacao/revealing-vital-elements-of-che... http://neworleanspelicansjerseys.spruz.com/pt/2-million-rifle-scale-crea... http://Utim.fr/blog/popularity-of-soccer-jerseys/

I used to be suggested this

I used to be suggested this web site by means of my cousin.
I'm now not positive whether this submit is written by him as nobody else recognize such specific approximately my problem.
You are wonderful! Thank you! http://www.16leaves.com/top-five-most-terrible-nfl-jerseys/ https://wna.ch/puppy-coaching-teaching-cheap-nfl-jerseys-your-dog-to-acc... http://quin.space/uncategorized/rss-feeds-feed-your-world-wide-web-rrnte...

If you want to obtain much

Quite interesting article,

Quite interesting article, how is your script can help me with the integration payment system in the website with music events http://bandstours.com ? But big thanks for your work! What if I can answer you on this?

com which is giving a FREE e

com which is giving a FREE e - Book to helpp get you started with your own survival
garden. Such featurfes aree all benefits of using laptop bags.
You buy one bag but actually with two different shapes.

I'm no longer certain where

I'm no longer certain where you are getting your info, but good topic.
I must spend some time finding out more or figuring out more.
Thank you for fantastic info I was on the lookout
for this info for my mission. http://www.konsciouscreations.com/201702/b04v2duxhy12 http://99jerseys.mee.nu/cheap_jerseysauthentic_pittsburgh_steelers_jerse... http://crazytennisbitches.com/guide-to-sports-activities-jerseys-cheap/

Pingback

[...] Puzzling Java statement of the day | antforge.org antforge.org/blog/2010/07/30/puzzling-java-statement – view page – cached Some days ago I stumbled across a Java statement which I thought was trivial at first, only to discover that I had no idea. I have a reasonable understanding of what a JVM does and how Java bytecode is executed. But as this example shows once again, that doesn’t necessarily spread to the Java programming language. The snippet below should explain my point. Tweets about this link [...]

I think you need help from

I think you need help from this guys http://ezcollegepapers.com , they can help you to beat your papers in college!

I like reading through a post

I used to be recommended this

I used to be recommended this blog through my cousin. I'm
now not positive whether this submit is written via him as no one
else realize such exact about my trouble. You're wonderful!
Thank you! http://clevelandbrownsjerseys.mihanblog.com/post/17 http://jerseysarizonacardinals.spruz.com/pt/2-expired-using-consignments... http://Cheapjerseysgo.mee.nu/?entry=2679628

I do trust all the ideas

I do trust all the ideas you've offered in your post. They're very convincing and will definitely work.
Still, the posts are too short for novices.

May you please lengthen them a bit from next time? Thanks for the post.
http://brooklynnetsjerseys.bcz.com/2018/01/28/and-moreover-ticklers/ http://iacdl-news.85859.x6.nabble.com/Area-performer-purchase-notorious-... http://wholesalejerseys4sale.mee.nu/?entry=2685407

I blog often and I truly

I blog often and I truly thank you for your content. This great article has truly peaked
my interest. I'm going to bookmark your website and
keep checking for new information about once per week.
I subscribed to your Feed too. http://www.wajieibrahim.com.my/2014/05/09/feel-the-rush-and-excitment-of... http://jerseysanaheimducks.mihanblog.com/post/27 http://xcheapjerseys.mee.nu/?entry=2679792