Eclipse中是否有任何功能可以重构我的代码,以便不合格的字段访问获得this限定符?例如,我在静态方法中编写了一些代码,但现在想将它们更改为非静态方法.我更喜欢使用我的代码样式,this以便它更清晰,更易读.
我想了一个简单的方法foo,并bar在这里:
public class Example
{
private static String foo = "Hovercraft";
private static int bar = 9001;
public static void main(String[] args)
{
System.out.println(foo + " has " + bar + " eels.");
}
}
Run Code Online (Sandbox Code Playgroud)
转入this.foo和this.bar更改代码后使用非静态方法:
public class Example
{
private String foo;
private int bar;
public class Example(String theFoo, int theBar)
{
this.foo = theFoo;
this.bar = theBar;
}
public void run()
{
System.out.println(this.foo + " …Run Code Online (Sandbox Code Playgroud)