---
title: "Java Errs"
author: "tkiicpp"
date: "2011-01-10T09:42:38Z"
tags: []
categories: ["编程语言"]
slug: "java-errs"
draft: false
lastmod: "2011-01-10T13:40:00Z"
id: 866674
url: "https://tkiicpp.iteye.com/blog/866674"
---

**"illegal modifier for parameter sum; only final is permitted**

 

The modifiers private, protected, and public cannot be used on variables inside of a method. This is because you can only have local variables inside of methods.

Java is simply telling you that the only modifier allowed at that time is the final keyword.

 

**Switch only applies to digit or one-char, not string**

 

```
在有多个选择路径的情况下，利用Switch可以使程序更加简洁有效。但由于其只能对整数选择因子进行判断，所以限制了其在其他类型尤其是String的使用，本文利用JDK1.5新推出的enum，实现了一种可以对String类型进行Switch的方法。直接看代码：

   1. enum EnumExample 
   2. {
   3.      Teamreq,Matreq;
   4. }
   5. public class EnumTest {
   6.     public static void main(String[] argc)
   7.     {
   8.         String str = "Matreq";
   9.         EnumExample test = EnumExample.valueOf(str);
  10.         switch (test)
  11.         {
  12.         case Matreq:
  13.             System.out.println("Matreq");
  14.             break;
  15.         case Teamreq:
  16.             System.out.println("Teamreq");
  17.             break;
  18.         default:
  19.             break;
  20.         }
  21.         
  22.     }
  23.
  24. }
转自：http://blog.csdn.net/pqw1157/archive/2009/01/06/3721619.aspx
```