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.
Hey very cool site!! Man ..
Hey very cool site!! Man .. Excellent .. Superb .. I'll bookmark
your blog and take the feeds additionally? I am glad to find a lot of helpful
info here within the put up, we'd like develop more techniques on this regard, thanks for
sharing. . . . . .
indeed!
indeed!
Hold up? An if statement
Hold up? An if statement function but no else? I'm shockeD!
Amazing things here. I'm very
Amazing things here. I'm very happy to peer your post.
Thanks a lot and I am having a look ahead
to touch you. Will you please drop me a e-mail?
Hi there everybody, here
Hi there everybody, here every person is sharing these kinds of familiarity, therefore it's pleasant to
read this blog, and I used to go to see this weblog all the time.
It's awesome in favor of me
It's awesome in favor of me to have a web site, which is good in favor of my knowledge.
thanks admin
It's awesome in favor of me
It's awesome in favor of me to have a web site, which is good in favor of my knowledge.
thanks admin
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>
Amazing! Its actually amazing
Amazing! Its actually amazing post, I have got much clear idea
about from this article.
Amazing! Its actually amazing
Amazing! Its actually amazing post, I have got much clear idea
about from this article.
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.
What's up to every one, it's
What's up to every one, it's actually a good for me to pay a visit this site,
it consists of valuable Information.
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.
What's up all, here every
What's up all, here every person is sharing such familiarity, so it's nice
to read this webpage, and I used to go to see this weblog
daily.
hi sir, is there any way we
hi sir, is there any way we can contact you? the thread here in antforge is scattered..
I delight in, cause I found
I delight in, cause I found just what I used to be having a look for.
You've ended my 4 day lengthy hunt! God Bless you man. Have
a nice day. Bye
excellent points altogether,
excellent points altogether, you simply gained
a new reader. What may you recommend about your publish that
you made some days in the past? Any certain?
excellent points altogether,
excellent points altogether, you simply gained
a new reader. What may you recommend about your publish that
you made some days in the past? Any certain?
Hello I am so thrilled I
Hello I am so thrilled I found your blog, I really found you by error, while I was searching on Google for something else, Anyhow I am here now and would just like to say thanks for a tremendous post and a all round enjoyable blog (I also
love the theme/design), I don't have time to read it all at the minute but I have bookmarked it and also included your RSS feeds,
so when I have time I will be back to read a lot
more, Please do keep up the fantastic job.
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.
I feel this is among the such
I feel this is among the such a lot vital information for me.
And i am glad studying your article. But want to commentary on some common things, The site taste is great, the articles is truly nice : D.
Good task, cheers
This page definitely has all
This page definitely has all of the information I needed concerning this subject and didn't know who to ask.
When I initially commented I
When I initially commented I seem to have clicked the -Notify
me when new comments are added- checkbox and from now on each time a comment
is added I recieve four emails with the same comment.
Perhaps there is an easy method you can remove me from that service?
Kudos!
When I initially commented I
When I initially commented I seem to have clicked the -Notify
me when new comments are added- checkbox and from now on each time a comment
is added I recieve four emails with the same comment.
Perhaps there is an easy method you can remove me from that service?
Kudos!
This is really fascinating,
This is really fascinating, You're a very skilled blogger.
I have joined your rss feed and look ahead to searching for more of your magnificent post.
Also, I've shared your site in my social networks
It's nice seeing here
It's nice seeing here informative content. Great work!
Awesome post!
Awesome post!
I am now not certain where
I am now not certain where you are getting your info, however good topic.
I must spend some time learning more or figuring out more.
Thanks for great information I used to be on the lookout for this info for
my mission.
Good day I am so glad I found
Good day I am so glad I found your blog, I really found you by
mistake, while I was searching on Google for something else, Anyhow I am here
now and would just like to say many thanks for a fantastic
post and a all round interesting blog (I also love the theme/design),
I don't have time to browse it all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more,
Please do keep up the excellent work.
Interesting post! Thanks for
Interesting post! Thanks for the share.
Hmm it looks like your
Hmm it looks like your website ate my first comment (it was super long) so I guess
I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog.
I as well am an aspiring blog blogger but I'm still new to everything.
Do you have any tips and hints for first-time blog writers?
I'd certainly appreciate it.
Yes! Finally something about
Yes! Finally something about technlogy.
Awesome post you shared.
Awesome post you shared.
Hi, this weekend is pleasant
Hi, this weekend is pleasant designed for me, as this moment i am reading this
fantastic informative article here at my home.
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.
Usually I don't read post on
Usually I don't read post on blogs, however I wish to say that this write-up very pressured me to take a look at and do it!
Your writing style has been surprised me. Thanks, quite great post.