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

My brother suggested I may

My brother suggested I may like this web site.
He was totally right. This post truly made my day.
You can not imagine simply how so much time I had
spent for this information! Thanks! http://jerseysanaheimducks.spruz.com/pt/-heroAshtone-Morgan-scored-that-... http://www.todogeologia.com/viewtopic.php?f=2&t=70248 http://Deensidewheelers.com/component/kunena/4-adverts/298381-the-first-...

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?

Hello, i believe that i

Hello, i believe that i noticed you visited my web site thus i got here to
go back the want?.I am attempting to to find issues to improve my website!I assume its ok to make use of
a few of your ideas!!post-39464http://www.aapaurary.com/forum/AAP_AUR_ARY_postsm5830_Carolina-Panthers-2017.aspxhttp://baidai8300.unblog.fr/2018/08/23/chronicle-the-actual-buffalo-grass-billing-accounts-cycling-cycling-tops/

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/

Wonderful goods from you,

Wonderful goods from you, man. I've take into accout your stuff previous to and you are
just too magnificent. I actually like what
you have bought right here, really like what you are stating and the best way in which you say it.
You're making it entertaining and you continue to take care of to keep
it sensible. I can not wait to read much more from you.
That is actually a wonderful web site.

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!

If you would like to obtain a

If you would like to obtain a good deal from this post then you
have to apply these techniques to your won web site.
http://www.chrlice.brno.cz/forum/viewtopic.php?f=8&t=57627 http://authentic-cheap-jerseys.mee.nu/?entry=2767440 http://minnesotawildjerseys.mee.nu/?entry=2766448

I like reading through a post

Nice post. I used to be

Nice post. I used to be checking constantly this weblog and I am impressed!
Extremely useful info particularly the remaining phase :) I handle such info a lot.
I used to be seeking this certain info for a long time.
Thanks and best of luck. http://traktorbetten.de/2597-2/ http://atlantabravesjerseys.Mee.nu/?entry=2770843 http://www.coolkidsbedding.com/482-2/

It's always cool to see ideas

It's always cool to see ideas people come up with
for kids.

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

Thank you for every other

Thank you for every other informative blog. The place else
could I am getting that type of info written in such an ideal way?
I have a mission that I'm just now working on, and I have been on the glance out
for such info. http://steffy.ro/forum?func=view&catid=3&id=35025 http://multie.mx/united-s-new-jerseys-number/ http://vipjerseysale.Mihanblog.com/post/14

Hi everyone, it's my first

Hi everyone, it's my first pay a visit at this web page, and
paragraph is really fruitful designed for me, keep up posting such articles.wholesale
nhl jerseyshttps://songexclusive.com/2015/02/20/video-tbt-sports-talk-january-31-2011/https://www.wearabletechnology.london/what-s-happened-in-mlb-on-transport/