Is there any way to cast an object based on a variable and not the actual object type?
For example I know I can do this:
public class testCast(Texas tx){ // Texas extends State
State state = null;
State = (Texas)tx;
}
What if I had an object of Texas but did not know the name of the class but had it in a variable instead?
public class testCast2(Texas tx){
State state = null;
stateName = tx.getClass().getName();
State = (stateName)tx
}
How would I do the equivalent of State = (stateName)tx where stateName is a String containing the name of the class.
For example I know I can do this:
public class testCast(Texas tx){ // Texas extends State
State state = null;
State = (Texas)tx;
}
What if I had an object of Texas but did not know the name of the class but had it in a variable instead?
public class testCast2(Texas tx){
State state = null;
stateName = tx.getClass().getName();
State = (stateName)tx
}
How would I do the equivalent of State = (stateName)tx where stateName is a String containing the name of the class.