package com.biubiu.example;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
/**
* @author :张音乐
* @date :Created in 2021/6/29 上午3:29
* @description:
* @email: zhangyule1993@sina.com
* @version:
*/
public class App {
/**
* 简单if else
* @param type
* @return
*/
private String simple(String type) {
String value = "";
if("type1".equals(type)) {
value = "";
} else if("type2".equals(type)) {
value = "";
} else if("type3".equals(type)) {
value = "";
}
return value;
}
/**
*
*/
private Map<String, String> templateMap = ImmutableMap.of("type1", "value1", "type2", "value2", "type3", "value3");
/**
* 优化简单 If else
* @param type
* @return
*/
private String optimize(String type) {
return templateMap.getOrDefault(type, "");
}
}
简单if-else代码优化
最新推荐文章于 2023-04-04 13:53:30 发布