Simple question but I have spent over an hour with this. My code is below. I need to make SomeClass sc dynamic. So you pass the class name as a string in a function and use that class in place of static someClass. How to go about it?
SomeClass sc;
if (someOtherClassObject instanceof SomeClass){
sc=(SomeClass) someOtherClassObject;
What I want is
public void castDynamic (String strClassName){
//cast the classname referred by strClassName to SomeClass
//if it is the instance of SomeClass
}
EDIT: The above was simplification. The actual code is this
public void X(String className, RequestInterface request)
{
//My current code is this, I need to change so that "XRequest"
//can be any class referred by "className",
//and "request.getRequest" the object belonging to "className" class
//I don't want static XRequest xvr, it should be fetched dynamically
XRequest xvr;
if (request.getRequest() instanceof XRequest){
xvr=(XRequest) request.getRequest();
client.setRequest(xvr);
}
}
Another simple rephrase: I get an object using request.getRequest(). I have no clue what that object is. So I need to cast it to the classstring name provided. How to do that? That's all. – SQC 13 mins ago