EDIT: enabled, see below
Hi,
In Java, I got an object that can be of any class. BUT - this object should always implement the interface, so when I call the methods defined by the interface, this object will contain this method.
Now, when you try to call a custom method on a shared object in Java, it tries to use typing. How can I somehow tell the compiler that my object implements this interface, so the method call is fine.
Basically, I'm looking for something like this:
Object(MyInterface) obj; // Now the compiler knows that obj implements the interface "MyInterface" obj.resolve(); // resolve() is defined in the interface "MyInterface"
How can I do this in Java?
ANSWER: OK, if the interface is called MyInterface, you can just put
MyInterface obj; obj.resolve();
Sorry I did not think before publishing ....
java interface
Jake
source share