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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:30:07+00:00 2026-05-25T22:30:07+00:00

I know how to get this code to work, but I’m curious why the

  • 0

I know how to get this code to work, but I’m curious why the compiler is not able to figure out that the call is to the outer class method:

public class Example {
    public void doSomething(int a, int b)
    {
    }

    public class Request
    {
        public int a;
        public int b;

        public void doSomething()
        {
            doSomething(a,b); // Error. Fix: Example.this.doSomething(a,b);
        }
    }
}

Is there a deeper design reason for this than protecting coders from making mistakes?

  • 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-25T22:30:08+00:00Added an answer on May 25, 2026 at 10:30 pm

    By the language definition, the outer-class method is not visible in the inner class because it is shadowed.

    Shadowing is based on name rather than signature. This is a good thing.

    Consider the alternative. You could hide a subset of method overloads. Someone else could try to change the arguments in a call, to call one of the other overloaded methods. Simply changing the arguments could cause the recipient object to change. This would be surprising, and could cost time to debug.

    From the Java Language Specification, 6.3.1:

    Some declarations may be shadowed in part of their scope by another
    declaration of the same name, in which case a simple name cannot be
    used to refer to the declared entity. A declaration d of a type named
    n shadows the declarations of any other types named n that are in
    scope at the point where d occurs throughout the scope of d.

    …

    A declaration d is said to be visible at point p in a program if the
    scope of d includes p, and d is not shadowed by any other declaration
    at p. When the program point we are discussing is clear from context,
    we will often simply say that a declaration is visible.

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

Sidebar

Related Questions

In code: //I know that to get this effect (being able to use it
I am trying to get this code to work for me,but It is not
Let's get this out of the way first: I know that SessionFactory is immutable
I know this is embarrassing easy but I cannot get this to work right
I have this code will work in multithreaded application. I know that immutable object
Anyone know how to get this to work if it's possible? class Foo def
I get the feeling this is probably something I should know but I can't
Hey I'm wondering how I can get this code to work. Basically I want
I've been trying to get this code to work for hours! All I need
I can't get this code to work if ($title != 'Main' || $nSpace ==

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.