public static int getCommand(byte[] bytes){
      String command=new String(bytes).trim();
return getCommand(command);
}
返回语句这么是写怎么解释?

解决方案 »

  1.   

    个人认为是防止byte【】数组转换为字符串后有空格等出现,那样转换为整形的时候应该抛出异常吧,但是你传的参数类型不同是不是还有重载啊,有一个参数为String类型的getCommand方法你没写啊?
      

  2.   

    重载的:
    public static int getCommand(String command){
    int comm=0;
    int start=command.indexOf('<');
    if(start==0){
    int end=command.indexOf('>');
    command=command.substring(start+1,end);

    if(command.equalsIgnoreCase("login")){
    comm=1;
    }
    if(command.equalsIgnoreCase("list")){
    comm=2;
    }
    if(command.equalsIgnoreCase("get")){
    comm=3;
    }
    if(command.equalsIgnoreCase("help")){
    comm=4;
    }
    if(command.equalsIgnoreCase("quit")){
    comm=10;
    }
    if(command.equalsIgnoreCase("ok")){
    comm=101;
    }
    }
    return comm;
    }
    }
      

  3.   

    传的参数是 string 的,为什么要写第一个方法
    第一个方法返回的什么
      

  4.   

    我认为只是普通的重载,这样既可以接受byte[]参数也可以接受String参数。
    至于方法里的处理,就是为了严谨吧。