If I have a class such as:
public class Main {
public class CommandLineParser {
public CommandLineParser(String[] args) {
}
}
public static void main(String[] args) {
Main main = new Main();
new CommandLineParser(args); // <<< line in question
}
}
then I, quite reasonably, get an error message:
No enclosing instance of type
Mainis accessible. Must qualify the allocation with an enclosing instance of typeMain(e.g.x.new A()wherexis an instance ofMain).
But if I move class CommandLineParser to a separate file there are no such complaints.
Why is there no error in the second case?
(NOTE: This question is NOT how to instantiate non static inner class within a static method.)