关于Switch的参数

在jdk 1.7之前:
switch只能传入int类型,由于char,short,byte的的精度比int小,所以可以默认转化为int类型
string,long,boolean,float精度比int大,所以无法作为参数
在jdk 1.7之后:
string,boolean,enum(枚举)可以作为参数传入,string的原理是由于string.hashcode()方法,将string类型转化为int类型

你可能感兴趣的:(j2SE基础知识,string)