Reputation: 4310
I can't remember the name of this concept.
public interface MainInterface {
public void method1();
public void method2();
}
void testMethod() {
methodMain(new MainInterface() {
@Override
public void method1() {
System.out.println("This is method1");
}
@Override
public void method2() {
System.out.println("This is method2");
}
});
}
void methodMain(MainInterface mi) {
mi.method1();
mi.method2();
}
What is this concept and how exactly it works?
Upvotes: 0
Views: 65
Reputation: 38195
The concept is referred to as callback. In java, you only have callback interfaces, in other languages you can have callback functions.
As a design pattern, this concept is involved in the strategy pattern (as amit already mentioned).
Upvotes: 0
Reputation: 20254
You have created an instance of an Anonymous Inner Class (i.e. a class without a name).
Upvotes: 3