小编Kyz*_*erp的帖子

如何在Eclipse中的Java字段中添加`this`限定符?

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.foothis.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)

java eclipse qualifiers this

2
推荐指数
1
解决办法
579
查看次数

标签 统计

eclipse ×1

java ×1

qualifiers ×1

this ×1