mercredi 25 février 2015

Can I pass a subclass instance to a method which accepts superclass instance

I have a setup similar to this. When I try to call execRequest method using java Reflections and in parameterArray pass the subclass instance which is DelRequest I am getting an NoSuchMethodFound Exception



lClass.getMethod( "execRequest", parameterArray)


This is my basic setup kindly point where am i wrong and can it be done or not



class DelRequest extends Request {
private String msg;


/* getters and setters */
}

class Request {
}



class ExecuteRequest{
public static String execRequest(Request request){
/* request do something*/
}

}





Aucun commentaire:

Enregistrer un commentaire