我正在创建应用程序的过程中,但我偶然发现了一个问题。
我正在创建一个程序,它将根据用户输入生成一个.java文件。在该程序中,您将能够选择自定义api(但不能提供给您)。一旦选择了API调用,就必须为该方法指定输入。您还可以指定另一个API调用作为当前参数的输入。我只想显示提供正确返回值作为所选api调用的输入的api调用。问题就在这里。我可以检测到所选api调用的参数的输入类型,但似乎无法检测到提供给listAPICallsWithReturnValue(...)的classValue参数的类型。函数的作用是:返回一个java.lang.reflect.Method对象。
我希望你们都能理解我的意思。:)
public void displayParameterDialogs(APICall call) {
JDialogMethodParameters dialog = new JDialogMethodParameters(mainframe, true);
for (int i = 0; i < call.getMethod().getParameterTypes().length; i++) {
dialog.init(i, call.getMethod().getParameterTypes()[i]);
dialog.setVisible(true);
}
}
//dialog class
public void init(int parameterIndex, Class parameterType) {
this.jLabelInfo.setText("Data for input parameter: " + parameterIndex);
DefaultComboBoxModel cmodel = new DefaultComboBoxModel();
for (APICall call : TestFactory.getInstance().listAPICallsWithReturnValue(parameterType)) {
cmodel.addElement(call);
}
this.jComboBox1.setModel(cmodel);
}
public APICall[] listAPICallsWithReturnValue(Class<?> classValue) {
APICall[] calls;
Vector<APICall> temp = new Vector<APICall>();
Method[] methods = TestSuite.class.getMethods();
for (Method method : methods) {
System.out.println(method.getReturnType().getName());
System.out.println(classValue.getClass().getName());
System.out.println(classValue.toString());
if (method.getReturnType().getCanonicalName().equals(classValue.toString())) {
temp.add(new APICall(method));
}
}
calls = new APICall[temp.size()];
return temp.toArray(calls);
}发布于 2011-05-20 22:58:36
也许:
classValue.getName()
classValue.getClass().getName()将返回“类”(因为classValue的类型是类)。
https://stackoverflow.com/questions/6073733
复制相似问题