为什么switch不能匹配long类型 简书___ 2023-10-07 110 阅读1分钟 switch可以匹配的类型: byte 、short 、int 、char、String 、枚举 为什么switch支持byte、short、int、char,不支持long、bool、float、double? 因为实际上switch只支持int。byte、short、char是先转换为了int再用来switch匹配。 为什么switch支持String?switch支持String其实就是语法糖。编译器会根据字符串的hashCode来处理