Possible Duplicate:
How are Anonymous (inner) classes used in Java?
i have a question about java. i saw this in many sources…
Class object = new Class()
{
// What is this, a subclass or what ?
public void someRandomMethod()
{
}
};
umm if is a subclass, when i make the object the class is executed automatically ? I’m confused
and sorry about my english, i try to do my best.
Many thanks !
It’s called an anonymous class. Yes, the class will automatically be extended. This pattern is most commonly used to create callback interfaces such as
RunnableorActionListener.This creates a new instance of
Runnableand passes it to theThreadfor execution. This was Java’s early substitute for closures.