Java7新特性Swith语句中支持String
实例:
public class StringSwitch {
public static void main(String[] args) {
System.out.println(getExpendedMessage("one"));
System.out.println(getExpendedMessage("three"));
System.out.println(getExpendedMessage("five"));
}
static String getExpendedMessage(final String token)
{
switch (token)
{
case ("one"):
return "Token one identified";
case ("two"):
return "Token two identified";
case ("three"):
return "Token three identified";
case ("four"):
return "Token four identified";
default:
return "No token was identified";
}
}
}
输出如下:
Token one identified
Token three identified
No token was identified
参考:click here
原文地址:http://blog.csdn.net/topwqp/article/details/46375595