First of all, consider using a different type of storage.
Here is an example that I whipped that does something effectively the same, and definitely compiles and runs:
import java.util.HashMap; import java.util.Map; class ItemMap { static Map<String, String> statuses = new HashMap<String, String>(); static { statuses.put("STATUS_NEW", "New"); } public static String getStatusFromString(String s) { for (Map.Entry<String, String> e : statuses.entrySet()) { if (e.getValue().equals(s)) { return e.getKey(); } } return ""; } } public class Item { public static void main(String[] args) { System.out.printf("Status for 'New': %s%n", ItemMap.getStatusFromString("New")); } }
The changes I would make are to change the map to use an enumeration instead of a string, and return the enumeration instead of a string. But it is up to you and your coding requirements.
This code definitely works for me.
source share