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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:06:37+00:00 2026-06-13T09:06:37+00:00

I have an object that I want to be modified when I call the

  • 0

I have an object that I want to be modified when I call the appropriate instance method for it. (I think that is the correct vocabulary)

From one class, I am doing this:

 Pizza pizza = new Pizza();
 pizza.addTopping(Cheese);
 pizza.addTopping(Pepperoni);
 pizza.setCrustType("thick");
 pizza.make();
 pizza.putInOven();

Here’s where things get interesting. So here’s the make() method that is called above that is in the class Pizza.

 public void make()
 {  
      final Pizza pizza = this;
      pizza.registerUpdateHandler(new IUpdateHandler()
      {             
           @Override
           public void onUpdate(float cookTime)
           {
                // need to do some modifications to pizza
                pizza.doSomething();
                pizza.doSomethingElse();
           }
      });
 }

In order to be able to access the pizza object inside the inner class, IUpdateHandler(), I have to set a Pizza object to this. But then, it also has to be final because you:

Cannot refer to a non-final variable inside an inner class defined in a different method.

Going back to my original code snippet, I still need to call pizza.putInOven() and have it be referencing the same Pizza object as all the other calls, but with the modifications from the make() method in effect. Because I had to create a new Pizza object of type final in the method make() that is no longer the same object modified when I want to call putInOven().

How do I solve this issue? If my question is not clear, I’ll do my best to edit and restate, just leave a comment.

  • 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-13T09:06:39+00:00Added an answer on June 13, 2026 at 9:06 am

    you don’t need the additional pizza variable because the code is already executed inside the pizza object.

    public void make(){  
          registerUpdateHandler(new IUpdateHandler(){             
               @Override
               public void onUpdate(float cookTime){
                    // need to do some modifications to pizza
                    doSomething();
                    doSomethingElse();
               }
          });
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one very general object that I want to map to a destination
I have an object that implements an interface. I want to call on the
I want to call JSON.stringify method from the C++ side with modified arguments, but
I have a method that I want to run iteratively on one of two
I have a SimpleXMLElement Object that I want to import with PHP. But it
I have a traceback object that I want to show in the nice format
I have a Python datetime object that I want to convert to unix time,
I have a custom principal object that I want to be able to serialize
I have an object of type Hash that I want to loop over via
I want to have a generic object that implements an interface. I mean if

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.