Hello!
Can I take a foreign class in Java which conforms to one of my custom interfaces and "cast" it to that interface?
Example:
public class YouCanNotChangeMe_IAmNotYours{
public void doSomethingSpecial();
}
public interface MyInterface{
void doSomethingSpecial();
}
Can I use that foreign class in places where my interface is expected?
Why do I need this at all?
I want to dynamically reload newer versions of some JAR at runtime, as I've mentioned here.
Now, the server knows all interfaces (knowing the former version of the JAR at compile time). The problem is, after loading classes from newer versions of that JAR at runtime, these "new" classes act as if they don't "know" the compile-time known interface.
Example: An old class, named HelloClass (known at compile time) does implement the interface HelloInterface, but the newly loaded class HelloClass does not implement that same interface!