[英]How do I re-factor references to static enum members
My code consists of references to enumeration in the following fashion. 我的代码包含以下列方式引用枚举的方法。
Flowers { ROSE, SUNFLOWER }
import com.mycompany.Flowers;
class A {
public void foo(...) {
Flowers flower = Flowers.ROSE;
}
}
I would like the above code to use static references to Flowers, the code would then look like 我希望上面的代码使用对Flowers的静态引用,然后代码看起来像
import static com.mycompany.Flowers.ROSE;
Flowers flower = ROSE;
How can I re-factor my code (using Eclipse) to use static references of enums instead of the normal referencing mechanism. 我如何重构我的代码(使用Eclipse)以使用枚举的静态引用代替常规的引用机制。 Is there a way to tell Eclipse to modify all regular enum references to static references?
有没有办法告诉Eclipse将所有常规枚举引用修改为静态引用?
That's probably not as proficient as you're looking for, but Ctrl + Shift + M on the reference of a static object will statically import it (works for members and methods alike)... That way you can achieve your static imports one-by-one. 这可能不像您想要的那样熟练,但是对静态对象的引用按Ctrl + Shift + M可以将其静态导入(适用于成员和方法)...这样一来,您可以实现静态导入-一一。
I'm interested too in other ideas, though 我对其他想法也很感兴趣
Here's how you can do it in two simple steps: 您可以通过以下两个简单步骤来完成此操作:
Flowers.NAME
to just NAME
. Flowers.NAME
更改为NAME
。 只需在单词Rose
上按Ctrl + Shift + M ,您将看到它是静态导入的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.