如何在NetBeans中封装局部变量

时间:2016-02-10 10:53:13

标签: java netbeans encapsulation

我想在NetBeans中将几个局部变量重构为内部或本地类。有没有办法使用重构工具来完成此操作,例如用于封装字段的move工具?

E.g:

public double calculate(){
    double a=2;
    double b=3.14159
    return a*b;
}

应该成为:

public double calculate(){
    NumberToCalc num = new NumberToCalc();
    return num.a*num.b;

}

class NumberToCalc{
    double a=2;
    double b=3.14159;
}

public double calculate(){
    class NumberToCalc{
        double a=2;
        double b=3.14159;
    }

    NumberToCalc num = new NumberToCalc();
    return num.a*num.b;
}

0 个答案:

没有答案