java中的Invoke方法
我需要编写一个代码来调用“transferControl”例程并从收件箱中读取信息。。在java中调用“transferControl”方法时,我的代码会是什么?请帮助我在java的新java中的Invoke方法,java,methods,invoke,Java,Methods,Invoke,我需要编写一个代码来调用“transferControl”例程并从收件箱中读取信息。。在java中调用“transferControl”方法时,我的代码会是什么?请帮助我在java的新 public class WhatNext { // // this method is invoked by the business logic to determine the // NextStep and set it in the receipient's Inbox. There is a su
public class WhatNext
{
//
// this method is invoked by the business logic to determine the
// NextStep and set it in the receipient's Inbox. There is a suggested
// InBox layout design in this code
//
public static void transferControl ( String requestId,
String businessTransactionId,
String transactionStepId,
String selector,
String requesterId)
{
InStorDB theDB = new InStorDB(); // "connect" to the DB
NextStep next = theDB.getNextStep(businessTransactionId,
transactionStepId,
selector);
//
// these 'columns' provide information on the next step to be taken
//
String nextTranId = next.nextBusinessTransactionId;
String nextStepId = next.nextBusinessStepId;
//
// which is then used to obtain the next initiation environment
//
CurrentStep current = theDB.getCurrentStep(nextTranId,
nextStepId);
//
// then used to set up the InBox fields of the recepient
// "to be coded"
//
// and stored in Inbox database
// "to be coded"
}
}
由于方法transferControl是静态的,您可以像下面这样调用该方法
WhatNext.transferControl(parameters);
简单地说:
WhatNext.transferControl(all parameters);
有可能的方法可以做到这一点,我将介绍两种方法: 由于transferControl方法是静态的,这意味着该方法不在各种对象之间共享,JVM将作为类级对象处理,因此您可以直接调用该方法,即
WhatNext.transferControl("requestId", "businessTransactionId",
"transactionStepId", "selector", "requesterId"); // values are dummy.
在第二种方法中,您可以使用反射来调用方法(不推荐),即
Class[]paramTypes=新类[5];
paramTypes[0]=String.class;
paramTypes[1]=String.class;
paramTypes[2]=String.class;
paramTypes[3]=String.class;
paramTypes[4]=String.class;
c类=Class.forName(“com.ankush.WhatNext”);
方法methodCall=c.getDeclaredMethod(“transferControl”,paramTypes);
对象[]obj={“requestId”,“businessTransactionId”,
“transactionStepId”、“selector”、“requesterId”};//值是虚拟的。
调用(null,obj);
很高兴看到评论。有些甚至会更好,因为她是java新手@Ankush@PiyushMittal我同意,但如果我们提供方法,这将有助于她,她将很快学会。非常感谢大家!
Class[] paramTypes = new Class[5];
paramTypes[0] = String.class;
paramTypes[1] = String.class;
paramTypes[2] = String.class;
paramTypes[3] = String.class;
paramTypes[4] = String.class;
Class<?> c = Class.forName("com.ankush.WhatNext");
Method methodCall = c.getDeclaredMethod("transferControl", paramTypes);
Object[] obj = {"requestId", "businessTransactionId",
"transactionStepId", "selector", "requesterId"};// values are dummy.
methodCall.invoke(null, obj);