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 9131609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:10:07+00:00 2026-06-17T08:10:07+00:00

I have a function that iterates over a heavy data set, receives a callback

  • 0

I have a function that iterates over a heavy data set, receives a callback (Google’s Guava Function) and runs the callback on every item of the data set:

void processData(..., Function<Item, Void> callback) {
  ...
  for (Item item : data) {
    callback.apply(item);
  }
} 

Using this function, I would like to pass a callback that adds all items to a list or a map:

List<Item> itemList;
processData(..., new Function<Item, Void)() {
  @Override public void apply(Item item) {
    itemList.add(item);
  }
});

However, it appears I can’t do that, since itemList is not final, and cannot be final by definition.

Is there a solution to this case? Or perhaps this entire pattern is wrong?

  • 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-06-17T08:10:08+00:00Added an answer on June 17, 2026 at 8:10 am

    You seem to have a incorrect understanding of the final keyword. This statement:

    final List<Item> itemList = new ArrayList<Item> ();
    

    only means that the itemList variable can’t be reassigned. It does not prevent you from modifying the object it points to and this call:

    itemList.add(someItem);
    

    is perfectly valid on a final List. What is not allowed would be to write:

    itemList = someOtherItemList; //forbidden, itemList is final
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my Controller i have function that runs after user clicks on item, which
I have a generic function that iterates over _meta.fields of a given object. All
I have the following function that iterates over a list [(Map String SqlValue)] extractPatternStrings
I have a try-catch block that iterates over a set of records like this:
I have a function that is passed two values and then iterates over the
Possible Duplicate: jQuery each this I have a loop that iterates over every element
I have a function that iterates through all HDD's on a computer, and returns
I have a function that takes an input string and then runs the string
I have the following jQuery method that iterates over a selectlist containing a number
I have a for loop that iterates over dependent fields in a form. The

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.