闂佽 鍋撻柟顖滃椤ワ拷 (0) +1 闁荤姍宥嗗 (0) +1 闂傚⿴浜烽幏锟� (0) +1
闂佽 鍋撻柟顖滃椤ユ垿鏌熺€涙ê濮囧┑顕嗘嫹闂佸搫琚崕鍐诧耿閸涙潙缁╅柟顖滃椤ワ拷>>

正在阅读:论全世界所有程序员都会犯的错误论全世界所有程序员都会犯的错误

2005-09-02 10:02 出处: 作者:Java-cn 责任编辑:moningfeng

  下面是我用javap来反组译程序1的示范:

C:>javap -c -classpath . Singleton

Compiled from MyMain.java
class Singleton extends java.lang.Object
{
public static int counter1;
public static int counter2;
public static Singleton getInstance();
static {};
}

Method Singleton()
0 aload_0
1 invokespecial
#1 <Method java.lang.Object()>
4 getstatic
#2 <Field int counter1>
7 iconst_1
8 iadd
9 putstatic
#2 <Field int counter1>
12 getstatic
#3 <Field int counter2>
15 iconst_1
16 iadd
17 putstatic
#3 <Field int counter2>
20 return

Method Singleton getInstance()
0 getstatic
#4 <Field Singleton obj>
3 areturn

Method static {}
0 new
#5 <Class Singleton>
3 dup
4 invokespecial
#6 <Method Singleton()>
7 putstatic
#4 <Field Singleton obj>
10 iconst_0
11 putstatic
#3 <Field int counter2>
14 return


  其实Java的syntactic sugar并不算多,C#的syntactic sugar才真的是无所不在,也因此C#的初学者更容易犯了“全世界所有程序员都会犯的错误”。

  许多C#的书都会一边介绍C#语法,一边介绍编译之后MSIL(.NET的中间语言,类似Java的Bytecode)的结果,然而Java的书却鲜少这么做。

  虽说是“全世界所有程序员都会犯的错误”,但是这不代表你犯了此错误之后,仍可以“抬头挺胸、理直气壮”。只要有心,其实这一类的错误仍是可以避免的。
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品
闂佸綊娼ч鍡椻攦閳ь剟鎮规担鍛婂仴婵☆偓鎷�闂佹悶鍎抽崑娑㈠春鐏炰勘浜滈柛顐f礀閸旓拷