WORKING WITH REFLECTION API


Step 1:  Create a Class Object where that Method Exists

Framework ex = new Framework();


Step 2: now create a object of Type METHOD

Method meth;


Step 3: Now we need to call, 

getClass() method of class object, which will return class object
then  call getDeclatedMethod(“MethodNAme”,TypeofArgument);:- it will return method object which is passed in first argument.

meth = ex.getClass().getDeclatedMethod(“readWorkBook1”,String.class); 

String.class
Int.Class
Null  : -  if no argument



Step 4: Use invokemethod of Method object to call that method.

meth.invoke(classobject,null)

Here in this, we need to pass classobject as a first argujment and data to the second argument.

meth.invoke(ex,null);


No comments :

No comments :

Post a Comment