日期:2014-05-20  浏览次数:20683 次

解释下用javap反编译后的代码
Java code
public class WhitherStringBuilder {
  public String implicit(String[] fields) {
    String result="";
    for(int i=0;i<fields.length;i++)
      result+=fields[i];
    return result;
  }
  public String explicit(String[] fields) {
    StringBuilder result=new StringBuilder();
    for(int i=0;i<fields.length;i++)
      result.append(fields[i]);
    return result.toString();
  }
}


Java code
public class WhitherStringBuilder extends java.lang.Object{
public WhitherStringBuilder();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public java.lang.String implicit(java.lang.String[]);
  Code:
   0:   ldc     #2; //String
   2:   astore_2
   3:   iconst_0
   4:   istore_3
   5:   iload_3
   6:   aload_1
   7:   arraylength
   8:   if_icmpge       38
   11:  new     #3; //class java/lang/StringBuilder
   14:  dup
   15:  invokespecial   #4; //Method java/lang/StringBuilder."<init>":()V
   18:  aload_2
   19:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
   22:  aload_1
   23:  iload_3
   24:  aaload
   25:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
   28:  invokevirtual   #6; //Method java/lang/StringBuilder.toString:()Ljava/la
ng/String;
   31:  astore_2
   32:  iinc    3, 1
   35:  goto    5
   38:  aload_2
   39:  areturn

public java.lang.String explicit(java.lang.String[]);
  Code:
   0:   new     #3; //class java/lang/StringBuilder
   3:   dup
   4:   invokespecial   #4; //Method java/lang/StringBuilder."<init>":()V
   7:   astore_2
   8:   iconst_0
   9:   istore_3
   10:  iload_3
   11:  aload_1
   12:  arraylength
   13:  if_icmpge       30
   16:  aload_2
   17:  aload_1
   18:  iload_3
   19:  aaload
   20:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
   23:  pop
   24:  iinc    3, 1
   27:  goto    10
   30:  aload_2
   31:  invokevirtual   #6; //Method java/lang/StringBuilder.toString:()Ljava/la
ng/String;
   34:  areturn

}

拣一些关键步骤说一下,
我只是好奇,感谢。

------解决方案--------------------
反编译是一种技术。在没有源码的情况下,它只会你要看的类的大概的方法属性反编译过来,
不会太具体,就是这样的,你大致了解一下类的作用大概就知道啦
------解决方案--------------------
楼主参考这个帖子:
http://www.iteye.com/topic/779102