Java多重判断的简化
http://my.oschina.net/u/1455908/blog/398481
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Java代码 package com.bjs.test; import java.util.Map; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; public class TestIf { public static void main(String[] args) { TestIf t = new TestIf(); int result = t.testMapReturn("A"); System.out.println(result); } private int testMapReturn(String gradle){ Map<String, Integer> configs = ImmutableMap.of("A",200,"B",4); Preconditions.checkNotNull(gradle); Integer result = configs.get(gradle); if(result==null){ return 0; } return result; } } |
