作爲傳統的C程序員,深覺得宏定義簡單,靈活,效率高。最近開始寫java代碼,沒有了宏,突然之間連怎麼寫判斷語句都不會了,總不能直接拿數字去判斷吧。
後來請教別人,找到了個替代的方法,在類裏聲明一個static 子類
public static class Type{
public static int TYPE1 = 1;
public static int TYPE2 = 2;
public static int TYPE3 = 3;
}
看似簡單,也有可能寫錯,記錄一下。
作爲傳統的C程序員,深覺得宏定義簡單,靈活,效率高。最近開始寫java代碼,沒有了宏,突然之間連怎麼寫判斷語句都不會了,總不能直接拿數字去判斷吧。
後來請教別人,找到了個替代的方法,在類裏聲明一個static 子類
public static class Type{
public static int TYPE1 = 1;
public static int TYPE2 = 2;
public static int TYPE3 = 3;
}