I have class A defined in a library:
public final class A {blah}
And then I want to hack it somewhere using a new class B to substitute it:
A a = new A();
A a = (A) new B();
B has all the methods and members in A, so it's actually safe to do this, and I can do it in C++. But for Java, this casting will result in an exception. So is there any workaround or hacking to do this in Java? In addition, is there a way to hack without touching the VM?
Though
Bhas all the methods and property doseAhave, you can not cast object ofBto a reference ofA. That means -is invalid unless
BextendsA.And here
Ais a final class so you can not extendsAbyB. You have to makeAnon-final and B has to extends A. Then the above casting will be valid.