I am working on anonymous
classes
and while working i come up with the case where i am unable to call a method using anonymous
class
.
I am getting following compilation error at m1()
The method m1(int) in the type new I(){} is not applicable for the arguments ()
interface I {
public void m1(int arg1);
}
class A {
static void m2(I i) {
}
}
class B {
class C {
void m4() {
A.m2(new I() {
public void m1(int arg1) {
m1();// Getting compilation error here.
}
});
}
void m1() {
System.out.println("Inside M1");
}
}
}
Can some one help me understand, why i am getting this error ? How to fix it
For those who does not understand the code please find the attached screen shot.