public class TestTypeTest { public static void main(String[] args) { // TODO Auto-generated method stub String feedback = "feedback"; if(TestType.FEEDBACK.equals(feedback)){ System.out.println("equal"+TestType.FEEDBACK); }else{ System.out.println("no"+TestType.FEEDBACK); } if(TestType.FEEDBACK.toString().equals(feedback)){ System.out.println("equal"+TestType.FEEDBACK.toString()); }else{ System.out.println("no"+TestType.FEEDBACK.toString()); } //这种才没问题 if(TestType.FEEDBACK.getFieldType().equals(feedback)){ System.out.println("equal"+TestType.FEEDBACK.toString()); }else{ System.out.println("no"+TestType.FEEDBACK.toString()); } } }
public enum TestType { FEEDBACK("feedback"); private String fieldType; private TestType(String fieldType) { this.fieldType = fieldType; } public String getFieldType() { return fieldType; } public static TestType getFieldType(String fieldType) { for (TestType type : TestType.values()) { if (type.getFieldType().equalsIgnoreCase(fieldType)) { return type; } } return null; } }