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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:30:31+00:00 2026-05-21T15:30:31+00:00

I have noticed in the code in my system that someone instantiated an anonymous

  • 0

I have noticed in the code in my system that someone instantiated an anonymous class as follows

 Class ExampleClass{

     MyObj obj; 

     methodA(new ClassA(){
         @override public void innerMethodA(){
            //code...
        }
    });
} 

So far so good.
Now, in order to use obj that was declared before the method I usually define it as final.
I don’t really understand why but i do because the compiler asks.
In this code i see in innerMethodA() the usage of

 ExampleClass.this.obj()

without final.

My questions :
1. why do I have to put final when I use obj?
2. what is ExampleClass.this ? Notice that ExampleClass is the Class not an instance. then what is the “this”? if it has several instances?
3. What happens if I change the obj while the inner method runs (in my code inner method runs in a loop so I plan on changing it . will it explode?)

  • 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-21T15:30:31+00:00Added an answer on May 21, 2026 at 3:30 pm
    • You have to use final when you capture the variable of a local variable… not an instance variable of the enclosing class.
    • ExampleClass.this is a reference to the instance of ExampleClass associated with the instance of the subclass of ClassA. In your case, it will be the same as this within methodA.
    • It won’t explode – it will just change the value of obj. Think of it as capturing the value of ExampleClass.this (so you can’t change that) but you can change the data within the object referred to by ExampleClass.this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that my geocoder is inconsistent in the code shown below because
I have noticed that cURL in PHP returns different data when told to output
I have noticed that some apps like Safari and Mail show a loading indicator
I have noticed that regardless of a given script's execution time, every date() call
I have noticed that my particular instance of Trac is not running quickly and
I have noticed over the years that different developers have different criteria for what
I have noticed that both IE6 and IE7 push the parent div down when
You may have noticed that we now show an edit summary on Community Wiki
I'm sure someone can explain this. we have an application that has been in
I have noticed jQuery (or is it Firefox) will turn some of my <span

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.