有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java存储方法值并验证该值是否为真

假设我在Netbeans中有两个项目Pro1'&;'Pro2'

我需要在Pro2中调用一个方法,它是public int method1Pro1。由于我在Pro1中调用了method1,所以我需要将method1的值存储在一个变量storeMethod1中,因此我需要检查存储的值是否正确

那我该怎么做呢?Pro1的代码示例正确吗

编辑:项目已添加到库中。除了if声明,一切都正常

Pro2代码示例:

public int method1(String a, String b, boolean c, String d, int e) {
    // basically, here will just create a function (eg: addUser/User registration)
}

Pro1代码示例:

public class Pro1 {
    ...
    public Response method1() {
        // intialize the variables

        //call the method in Pro2
        Pro2 pro2 = new Pro2();
        int storeMethod1 = pro2.method1(a, b, c, d, e);

        //return the storeMethod1 if able to call method1
        if (storeMethod1 == pro2.toString(method1)) {
             returnData.put("message" , "Success");
        } else {
             returnData.put("message", "Invalid Input");
        }

        return Response.ok (gson.toJson(returnData), MediaType.APPLICATION_JSON).build();
    }
}

提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    您需要将“项目2”添加到“项目1”库中

    要在netbeans中实现这一点:

    1. 右键单击项目1
    2. 选择“属性”
    3. 选择“库”
    4. 选择“编译”
    5. 选择“添加项目”
    6. 选择项目2
    7. 点击“确定”