Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:02:57+00:00 2026-05-22T19:02:57+00:00

I got a code review remark today to extract this anonymous class into a

  • 0

I got a code review remark today to extract this anonymous class into a field, to avoid allocating it over and over again:

Collections.transform(new Function<Foo, Bar>(){
  Bar apply(Foo foo) {
    // do some simple local transform of foo into a Bar.
  }
});

I replied that “it doesn’t matter, the JVM optimizes it”. While I know for a fact that this “optimization” won’t affect the performance in any way and I think the added value of having the code accessible inline is worth it, I’m curious if I was right about the JVM optimization.
So, my question is – it the proposed refactoring absolutely a no-op, because the JVM will optimize it anyway, or is there some minuscule theoretical perf gain here?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:02:57+00:00Added an answer on May 22, 2026 at 7:02 pm

    I wouldn’t particularly expect it to optimize that, no.

    It would have to make sure that Collections.transform never stashed away the Function, and that the method itself never makes this visible etc. Obviously all that’s doable – but it would potentially be quite a lot of work for a relatively small gain in a very few situations.

    Now what any particular VM does is hard to say without very careful examination – but I think “It’s not going to affect performance significantly” is a more reasonable thing to say than “The JVM optimizes it.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this question when I received a code review comment saying virtual functions
I've got code similar to this: string s = CreateString(); if (s == )
I've got code like that: <ul class=gallery_demo_unstyled> <li class=active><img src='001.jpg' /></li> <li><img src='002.jpg' /></li>
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I got this code in order to build an url for the link using
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
Currently I got this code: function post_positive(id) { if (window.XMLHttpRequest) { xmlhttp = new
I got another problem with the FCKEditor within ASP.NET MVC. Please review the code
I have a problem. You see, I've got this code (MVC3) @Using Html.BeginForm() @Html.ValidationSummary(True,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.