Suppose i have a interface like this,
interface MyIntf{
void generate();
}
and a method like below
void run(Myintf x) {
x.generate();
}
I could call run() with an object of a class which implements MyIntf.
but is it possible in Java to declare run without an explicit name for the interface.
i.e. can i specify run() like this?
void run("Some object which has a method called 'void generate()'" x){
x.generate();
}
and run() can be called with an object of any class which has a method called
void generate();
Java uses “nominative” rather than “structural” typing.
Just because a method has the same name and parameters, doesn’t mean it does the same thing (put the camera/gun to you head and shoot). If you need to make a legacy type conform to a particular interface, use an adapter. Avoid reflection.