File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes anonymous class in methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "anonymous class in methods" Watch "anonymous class in methods" New topic
Author

anonymous class in methods

Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

what do you call a anonymous class defined inside a method???

For eg; What do I call the class inside mtd() in class A ???



class B{
public void mtdb(){
System.out.println("hey1");

}

}

public class A{


public static void main(String sinful[]){

A a= new A();
B b = new B();

a.mtd();
b.mtdb();
}

void mtd(){

B b = new B(){

public void mtdb(){
System.out.println("hey");
}

};

b.mtdb();

}


If you are not laughing at yourself, then you just didn't get the joke.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I don't know a more specific term than "anonymous inner class"...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

can we call it anonymous local class.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Arun Kumarr:
can we call it anonymous local class.


You could; you could also call it "Harold", if you wanted. But officially, it's an anonymous inner class, and that's what everyone calls it.

There is no such thing as a "non-local anonymous class", right? So the "local" would be redundant.


[Jess in Action][AskingGoodQuestions]
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

when I said "local" I meant "method-local" anonymous inner class.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Well, as they don't work differently from "non-method-local" ones, why would you want to give them a special name?
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Plus its not method local as it can be accessed as if it were class local, i.e. anonymous inner class.

correct me if I am wrong here.
 
jQuery in Action, 2nd edition
 
subject: anonymous class in methods
 
Similar Threads
Is there a way to instantiate anonymous inner class?
Question on Anonymous Inner class
Argument-defined anonymous class call
Pls help- write a code with anonymos class, indicate with a comment line in the code
Anonymous inner class