且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从它的类中提取一个方法(并进入一个新的或现有的)?

更新时间:2023-12-02 21:39:22

public void Method() {}

public void Method() {}

  1. 首先,使用使方法静态"命令将方法设为静态.

  1. First, make the method static using the "Make Method Static" command.

public static void Method(){}

public static void Method(){}

然后,添加一个新类的类型的局部变量:

Then, add a local variable of the type of the new class:

public static void Method(){Class2 me = new Class2();}

public static void Method(){Class2 me = new Class2();}

然后,使用引入参数

public static void Method(Class2 me) {}

public static void Method(Class2 me) {}

然后使用使方法非静态".在 class2 中:

Then use "Make Method non-Static". In class2:

public void Method(){}

public void Method(){}