Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

anonymous class in methods

 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

}
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know a more specific term than "anonymous inner class"...
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we call it anonymous local class.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I said "local" I meant "method-local" anonymous inner class.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic