jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Instantiating Local Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Instantiating Local Classes" Watch "Instantiating Local Classes" New topic
Author

Instantiating Local Classes

Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24


The above code is from a book. I'm unable to understand what the author means by " In the non-static method, the reference to the instance of the enclosing context is passed implicitly in the constructor call of the non-static local class at (6). "
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Inner Story (<= click) .

download a good decompiler (for example jad) , and open the inner classes. surprisingly you can find a different default constructor !
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Seetharaman I looove campfire stories Liked the Pass-by-value Please story

Thanks for sharing the link and for your response

Downloaded JD-GIU (a java decompiler) and decompiled the following code :


FOUND THIS :



Now my question is - is there some specification about how class files would be named once we define inner classes - like it shows $ as a seperator; and $1 as a seperator for local classes?
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 196
    
    5
Vishnu,

Now my question is - is there some specification about how class files would be named once we define inner classes - like it shows $ as a seperator; and $1 as a seperator for local classes?


$ followed by an integer is used for local classes because you can declare multiple local classes with the same name, in different methods. The following code adds a definition of local class 'InsideMethod' in 'method2()':



When you compile the above class, the Java compiler will generate the following class files for the local inner classes 'InsideMethod' defined in 'method()' and 'method2()':

Outer$1InsideMethod.class
Outer$2InsideMethod.class

With respect,
Mala


Author of book OCA Java SE 7 Programmer I Certification Guide from Manning
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Thanks for your response Mala
Abdullah mohammad
Greenhorn

Joined: Feb 22, 2013
Posts: 3
Seetharaman Venkatasamy wrote:Inner Story (<= click) .

download a good decompiler (for example jad) , and open the inner classes. surprisingly you can find a different default constructor !
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
 
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.
 
subject: Instantiating Local Classes
 
Similar Threads
anonymous class giving compile time error
which draw() is called?
Constructors and Polymorphism
instanize interface?
Can any one please explain this