Is there a way to pass enum value from the string?
So that I can make event.getType() to return enum of the string instead of
returning string?
On Friday, July 18, 2014 1:22:45 PM UTC-4, Streets Of Boston wrote:
>
> Yep, you can't do that.
>
> If 'event' is of type 'Type', then you could do "switch(event) { case
> TYPE_ONE: .... case TYPE_TWO: ...} ...", because Enum values are considered
> to be constant.
>
> Instead, change your switch statement to "if (...) else if (...) { ... }
> else if (...) { ... } else if (...) { ...} .. ..." statements. A bit more
> typing, but works well :)
>
> On Friday, July 18, 2014 11:57:03 AM UTC-4, sweety fx wrote:
>>
>> *I have the below enum:*
>>
>> public enum Type {
>>
>> TYPE_ONE("event/one");
>> TYPE_TWO("event/two");
>>
>> private Type(String mType){
>> this.mType = mType;
>> }
>> private final String mType;
>>
>> public String getType(){return mType;}
>> }
>>
>> *I am trying to compare in Switch/Case:*
>>
>> switch (event.getType()){
>> case Type.TYPE_ONE.getType(): // says
>> "Constant expression required"
>> Do something:
>> case Type.TYPE_TWO.getType(): // says
>> "Constant expression required"
>> Do something;
>> }
>>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.