标签:switch 语句中的string java7 jdk7
Jdk7新增的switch 语句中常量可以string类型,
例如:
@Test
	public void test_1(){
		String string = "hello";
		switch (string) {
		case "hello":
			System.out.println(string);
			break;
		default:
			throw new IllegalArgumentException("非法参数");
		}
	}所以string 类型不能为 NULL.
例如:
@Test
	public void test_3(){
		String string = null;
		expectedException.expect(NullPointerException.class);
		switch (string) {
		case "hello":
			System.out.println(string);
			break;
		default:
			throw new IllegalArgumentException("非法参数");
		}
	}NullPointerException
标签:switch 语句中的string java7 jdk7
原文地址:http://blog.csdn.net/doctor_who2004/article/details/40592633