I guess I did not yet get the concept of Enum
s in Java.
I try to compare Strings to my Enum-entries comparable to Special characters in an enum.
package com.stackoverflow.tests;
public class EnumTest {
enum EnumTestOperator {
EQUAL("=="),
NOT_EQUAL("!=");
private String value;
private EnumTestOperator(String value) {
this.value = value;
}
public String toString() {
// will return == or != instead of EQUAL or NOT_EQUAL
return this.value;
}
}
public static void main(String[] args) {
String line;
line = "<>";
line = ".ne.";
line = "!=";
// Operator
switch(line) {
// case "!=":
case EnumTestOperator.NOT_EQUAL:
System.out.println("Not Equal");
break;
default:
System.out.println("Something else");
break;
}
}
}
But in the Line:
case EnumTestOperator.NOT_EQUAL:
I get a compiler error:
Type mismatch: cannot convert from EnumTest.EnumTestOperator to String
What am I doing wrong?