I'm aware that this could be a possible duplicate, but the other threads haven't solved my problem completely.
Let's say I have the following classes A and B which extend BasicClass.
public abstract class BasicClass {
// ...
}
public class A extends BasicClass {
// ...
}
public class B extends BasicClass {
// ...
}
And now I want to cast class A to B dynamically.
a.getClass().cast(bClass.newInstance);
but every time I get an Exception.
java.lang.ClassCastException
at java.lang.Class.cast(Unknown Source)
Can you tell me why?