首页 新闻 会员 周边

java使用状态模式如何替换if else

0
[待解决问题]
public class StateTest {
    public static void main(String[] args) {
        String str = "test";
        if (str.equals("test")) {
            System.out.println("test");
        } else if (str.equals("hello")) {
            System.out.println("hello");
        } else {
            System.out.println("world");
        }
    }
}

如何用状态模式优化上面的if else

何甜甜在吗的主页 何甜甜在吗 | 菜鸟二级 | 园豆:357
提问于:2018-10-29 20:24
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册