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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:14:16+00:00 2026-05-21T20:14:16+00:00

I noticed a peice of code I was looking at, that the author used:

  • 0

I noticed a peice of code I was looking at, that the author used:

class MainClass
{
  protected int someVar = 1;

  private SomeClass someClass = new SomeClass(this, new SomeActionListener() {
    protected void onAction() {
      MainClass.this.someVar ++;
    }
  });

  public MainClass()
  {
  }
}

Note how he used MainClass.this to get the proper context of ‘this’ to change the scope back to MainClass. I’ve never seen this done before – can someone explain?

  • 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-21T20:14:17+00:00Added an answer on May 21, 2026 at 8:14 pm

    The anonymous instance is bound to the scope of the instance in which it is created. Therefore it can also access everything within. this would refer to the anonymous instance and MainClass.this to the instance in which the anonymous instance was created. If for example the someClass member would have been declared as static, you could not have used MainClass.this.

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

Sidebar

Related Questions

I was looking at a piece of code today and notice that this particular
I have noticed this piece of code: FileInfo[] files =new DirectoryInfo(@C:\).GetFiles(); What is the
I'm looking for a simple piece of code that will change all the backslashes
I noticed when doing a query with multiple JOINs that my query didn't work
I noticed while playing around with Chrome that both of these functions work the
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot
I was just looking around rails and noticed there is an app controller but
I have started initially with VC++ 2008 Express. I've noticed that GCC becomes kind

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.