来看看java 反编译出来的东西,详细理解i++与++i

public class Inc {
	public static void main(String[] args) {
		int j = 0;
		j = j++ + j++;
		System.out.println(j);
	}
}//1


D:\Eclipse\eclipse-3.5.0\test\bin>javap -c Inc

Compiled from "Inc.java"
public class Inc extends java.lang.Object{
public Inc();
  Code:
   0:   aload_0
   1:   invokespecial   #8; //Method java/lang/Object."":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   iconst_0
   1:   istore_1
   2:   iload_1
   3:   iinc    1, 1
   6:   iload_1
   7:   iinc    1, 1
   10:  iadd
   11:  istore_1
   12:  getstatic       #16; //Field java/lang/System.out:Ljava/io/PrintStream;
   15:  iload_1
   16:  invokevirtual   #22; //Method java/io/PrintStream.println:(I)V
   19:  return

}

public class Inc {
	public static void main(String[] args) {
		int j = 0;
		j = ++j + ++j;
		System.out.println(j);
	}
}//3

D:\Eclipse\eclipse-3.5.0\test\bin>javap -c Inc

Compiled from "Inc.java"
public class Inc extends java.lang.Object{
public Inc();
  Code:
   0:   aload_0
   1:   invokespecial   #8; //Method java/lang/Object."":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   iconst_0
   1:   istore_1
   2:   iinc    1, 1
   5:   iload_1
   6:   iinc    1, 1
   9:   iload_1
   10:  iadd
   11:  istore_1
   12:  getstatic       #16; //Field java/lang/System.out:Ljava/io/PrintStream;
   15:  iload_1
   16:  invokevirtual   #22; //Method java/io/PrintStream.println:(I)V
   19:  return

}

public class Inc {
	public static void main(String[] args) {
		int j = 0;
		j = ++j + j++;
		System.out.println(j);
	}
}//2


D:\Eclipse\eclipse-3.5.0\test\bin>javap -c Inc

Compiled from "Inc.java"
public class Inc extends java.lang.Object{
public Inc();
  Code:
   0:   aload_0
   1:   invokespecial   #8; //Method java/lang/Object."":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   iconst_0
   1:   istore_1
   2:   iinc    1, 1
   5:   iload_1
   6:   iload_1
   7:   iinc    1, 1
   10:  iadd
   11:  istore_1
   12:  getstatic       #16; //Field java/lang/System.out:Ljava/io/PrintStream;
   15:  iload_1
   16:  invokevirtual   #22; //Method java/io/PrintStream.println:(I)V
   19:  return

}


你可能感兴趣的:(java,eclipse,class,string,java)