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 ofg()
is dead code. - Just
g()
is invoked and the call-site off()
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.
You have a great content!
You have a great content! Thanks for sharing
I'm so happy with the
I'm so happy with the content! Thanks
You have a good details!
You have a good details! Thanks
You have a good content!
You have a good content! Thanks
Thanks for this information!
Thanks for this information! Keep it up
You have a nice data! Thanks
You have a nice data! Thanks
You have a good content!
You have a good content! Thanks
I'm so impressed with the
I'm so impressed with the output! Thanks
I want to share this content!
I want to share this content! Thanks
This is great. I appreciate
This is great. I appreciate the post. Seriously.
Informative Blog. Thanks for
Informative Blog. Thanks for sharing.
Thanks for making this
Thanks for making this content so informative!
Hold up? An if statement
Hold up? An if statement function but no else? I'm shockeD!
Love the whole idea! Thanks
Love the whole idea! Thanks <a href="https://schafersrealestate.com/buyers/deciding-to-buy/">Homes for sale in Cincinnati Ohio</a>
I am truly pleased to
I am truly pleased to discover this website. Thanks a lot!
Informative post, thanks for
Informative post, thanks for the share.
Thanks for sharing, this
Thanks for sharing, this showcase the complexities that can arise in programming languages and the importance of fully understanding them to avoid errors and confusion.
Loops in Java come into use
Loops in Java come into use when we need to repeatedly execute a block of statements.
Finally find the info someone
Finally find the info someone asked the other day about Hugh Jackman on https://www.celeb-networth.com/ I was looking for it all over the web and luckily found it!
Java for the win, always and
Java for the win, always and forever. Seriously!
This is awesome.
This is awesome.
hi sir, is there any way we
hi sir, is there any way we can contact you? the thread here in antforge is scattered..
It's nice seeing this site
It's nice seeing this site again.
Interesting site to visit,
Interesting site to visit, great work.
Awesome post! Thanks for this
Awesome post! Thanks for this great share.
I know this is quality based
I know this is quality based blogs along with other stuff.
It's nice seeing here
It's nice seeing here informative content. Great work!
Awesome post!
Awesome post!
Interesting post! Thanks for
Interesting post! Thanks for the share.
Awesome post you shared.
Awesome post you shared.
I'm glad checking this great
I'm glad checking this great content here.
Awesome content, looking
Awesome content, looking forward to seeing more posts.
Interesting post you shared.
Interesting post you shared.
Wow. this blog was very
Wow. this blog was very useful. Thank you.
Simple to understand and
Simple to understand and helpful. We will look forward for your future updates.Thanks!
This is a great blog. Thanks
This is a great blog. Thanks for sharing this one.
It is always great to stumble
It is always great to stumble across an interesting topic of yours like this.
Great site thanks admin. More
Great site thanks admin. More power
Thank you for posting this. I
Thank you for posting this. I did not know that this existed and gave me really good information that I can use in the future.
Check out https://pghguttercleaning.com/blog/ for other helpful posts of your interest.
I'm puzzled. This reminds me
I'm puzzled. This reminds me a lot about lorem ipsum. There's a story behind that though. Anyway, please drop by or visit https://www.airanddryerventcleaninggilbert.com/ for quality air duct and dryer vent cleaning in Gilbert, AZ.
Thank you for
Thank you for sharing
http://google.com
Such an informative site!
Such an informative site! Thank you.
I like this site it’s a
I like this site it’s a master piece! Glad I noticed this on google.
Looking forward to more great
Looking forward to more great posts from this site.
Same here. I'm glad that they
Same here. I'm glad that they shared this with us. Now, I learned something new. Anyway, if you need flooring for your home in Mesa, I suggest you get the installation from https://www.floorinstallationmesa.com for quality with affordability.
Thanks for sharing this one.
Thanks for sharing this one.
Glad to find this site, keep
Glad to find this site, keep on posting
I love coding using Java.
I love coding using Java.
Thanks for sharing this great
Thanks for sharing this great article.
Glad to check this awesome
Glad to check this awesome site. I like the content of this article very informative one.