I have trouble understanding why the following code could compile fine
The Output is: asdf at position #1, the innerclass is instantiating as if the inner class is a static nested class, but clearly it isn't, it is only a regular inner class. How is this possible? Thanks in advance for helping
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
First, "Outer" is not required. The program works without it. Second, what is the actual name of the Inner class? It is Outer.Inner. So all you are saying is instantiate an Inner object using it's qualified name. This would not work from any context other than inside the Outer class.
Hi! This is a real goof up on the syntax, or the already-weird syntax of Inner Classes. Inside the callingInside () Method if I use this.new Inner().hello(); I get the same output. And according to Kathy and Bates I shud. Bartenders, any lights on this???
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Originally posted by Manvir Singh: Hi! This is a real goof up on the syntax, or the already-weird syntax of Inner Classes. Inside the callingInside () Method if I use this.new Inner().hello(); I get the same output. And according to Kathy and Bates I shud. Bartenders, any lights on this???
Again, what is the name of the inner class? Remember that "this" represents an instance of the Outer object. If "a" was an instance of the Outer object then wouldn't this be legal: a.new Inner().hello(); So why shouldn't I be able to replace "a" with "this" as long as I am in an Outer context?
Michael Zalewski
Ranch Hand
Joined: Apr 23, 2002
Posts: 168
posted
0
I don't see why you think that there is anything static about #1. Nothing is static except the main() method.
I guess the confusion is that is invoked via the name of the class instead of the name of an object. So it looks kind of like a static invocation. But the same is true for all constructors. What would a non-static constructor invocation look like?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.