I have a ENUM defined as;
public enum YesNoEnum {
Y,
N
}
I am using this for one of my values voted.
So I use it within a loop (looping over object array from query response)
person.setVoted(responseArray[1] != null ? YesNoEnum.valueOf((String)responseArray[1]) : null);
I have the setter as
public void setVoted(YesNoEnum voted) {
this.voted = voted;
}
Now I am getting an exception if the value for responseArray[1] is Y/N
If I debug/watch responseArray[1] , it shows type as YesNoEnum and shows value as "Y"
It says
cannot cast an instance of YesNoEnum to an instance of String
String[] responseArray?responseArraydeclared?Stringin Java, always use `toString()'. Casting is in general a bad idea in Java except when you have checked the type beforehand.