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

  • Home
  • SEARCH
  • 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
  • 0 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 got the code below how do I pass the current object this into
I've got this code: rs1 = getResults(sSQL1) rs2 = getResults(sSQL2) rs1 and rs2 and
I was doing some code review today and came across an old code written
I'm experimenting on this code that I got from the net (I'm trying to
I got my code like the following: class TimeManager { public: virtual ~TimeManager(); };
I got this code from w3schools, and tweaked it based on this one: Rename
I have a problem. You see, I've got this code (MVC3) @Using Html.BeginForm() @Html.ValidationSummary(True,
I've got code similar to the following... <p><label>Do you have buffet facilities?</label> <asp:RadioButtonList ID=blnBuffetMealFacilities:chk
I got the code of a former employee. There are many calls to methods

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.