繁体   English   中英

遍历许多枚举结构时重构和删除“ for”语句

[英]refactoring and removing 'for' statements when circling over many enum structures

我的班级有一个Enum作为属性。 它使用字符串来设置此属性。 有许多枚举类。 我该如何重构?

public void setType(String s) {  

for (MyEnum1 e : MyEnum1.values()) {  
    if (e.name().equalsIgnoreCase(s))  
    this.type = e;  
}  
for (MyEnum2 e : MyEnum2.values()) {  
    if (e.name().equalsIgnoreCase(s))  
    this.type = e;  
}  
for ...  

提前致谢。

使用MyEnum1.valueOf(String)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM