---
title: "switch语句能否作用在byte上，能否作用在long上，能否作用在String上？"
author: "guo2168"
date: "2010-12-27T17:02:44Z"
tags: []
categories: ["编程语言"]
slug: "switch-byte-long-string"
draft: false
lastmod: "2010-12-27T17:02:44Z"
id: 853036
url: "https://guo2168.iteye.com/blog/853036"
---

在switch(exp)中，exp只能是一个整数表达式或者枚举常量(javase5)，整数表达式可以是int基本类型或Integer包装类型，由于byte,short,char都可以隐含转换为int，所以这些类型以及这些类型的包装类型也是可以的。显然long和String类型都不符合switch语法的规定，并且不能隐式的转换成int类型，所以它们不能作用于switch语句中，此时只能只能使用一系列的if等语句了。