1
我正在將Java(JDK 1.5)「枚舉」轉換爲Java ME(JDK 1.4)。Java ME:將基本JDK 1.5「枚舉」對象轉換爲Java ME CLDC-1.1/IMP-NG(JDK 1.4)
很多人都建議使用retroweaver將JDK 1.5庫解析爲JDK 1.4,但使用它時遇到了很多問題,並且由於硬件限制,我真的想完全控制我的項目。
什麼是翻譯它或找到等價物的最佳方法?
/**
Authentication enumerates the authentication levels.
*/
public enum Authentication
{
/**
No authentication is used.
*/
NONE,
/**
Low authentication is used.
*/
LOW,
/**
High authentication is used.
*/
HIGH,
/*
* High authentication is used. Password is hashed with MD5.
*/
HIGH_MD5,
/*
* High authentication is used. Password is hashed with SHA1.
*/
HIGH_SHA1,
/*
* High authentication is used. Password is hashed with GMAC.
*/
HIGH_GMAC;
/*
* Get integer value for enum.
*/
public int getValue()
{
return this.ordinal();
}
/*
* Convert integer for enum value.
*/
public static Authentication forValue(int value)
{
return values()[value];
}
}
這實際上取決於您在代碼中依賴枚舉的獨特功能的程度。如果沒有任何東西想要序列化或做任何事情,你可以用類來模擬枚舉並實現你正在使用的特定功能。如果你不需要類型安全,你甚至可以決定用普通常量替換枚舉。 – RealSkeptic
我用普通常量替換所有東西可能會起作用。我會試着看看它是否有效。 TNX –