Original Post
Consider the following: How do I call the Outer's doSomething() from within the Inner's doSomething()? The only thing I found that compiles is to have Inner extend Outer and use super. , but this makes no logical sense for my design at all. (Actually, I can't imagine a case where it would ever make sense.) EDIT: The following works, but I still can't believe I would have to do something like this: The thing is, in the actual code, the analogue of 'doSomething' is the only reasonable name for the method... and a large part of the purpose of Inner is to encapsulate a parameter for the doSomething call.
class Outer {
public void doSomething(int x) { System.out.println(x); }
class Inner {
public void doSomething() {
// Outer.doSomething(42); <-- doesn't work; doSomething() is not static
// doSomething(42); <-- doesn't work; the compiler looks for the method in
// Outer.Inner first, and complains that it can't be applied to (int)
// this.doSomething(42); <-- doesn't work; same problem
}
}
}
class Outer {
public void doSomething(int x) { System.out.println(x); }
private void doSomething_redirect(int x) { doSomething(x); }
class Inner {
public void doSomething() {
doSomething_redirect(42);
}
}
}