Java Errs

"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.youkuaiyun.com/pqw1157/archive/2009/01/06/3721619.aspx
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值