• Advertisement
Sign in to follow this  

I love using emuns but experts advise not to

This topic is 471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Enums are so easy and adaptable. I luv em but a few articles I've read advised not to use them in android for performance issues. Phones are changing, todays phones can run unreal engine 4. Should I ignore this advice and use my dearly beloved enums or use the static ints finals they advised?

Edited by LAURENT*

Share this post


Link to post
Share on other sites
Advertisement

Java's definition of an enum is different than most other languages.  

 

In most languages, enums effectively vanish and become an integer constant. In languages with reflection there is a shared piece of data plus the individual integral values.

 

In Java, an enum is a specially generated class, where values are global instances of the class. This gives them a little extra baggage you don't get with an integral value. Enums can have instance methods and data, and other things found in class objects.

 

 

If an enum is the right solution for you code then use it.  If an integer value is a better solution for your code, use it instead.

Share this post


Link to post
Share on other sites

Java's definition of an enum is different than most other languages.  

 

In most languages, enums effectively vanish and become an integer constant. In languages with reflection there is a shared piece of data plus the individual integral values.

 

In Java, an enum is a specially generated class, where values are global instances of the class. This gives them a little extra baggage you don't get with an integral value. Enums can have instance methods and data, and other things found in class objects.

 

 

If an enum is the right solution for you code then use it.  If an integer value is a better solution for your code, use it instead.

 

I like the adaptablity of enums and I used them quite a bit in another project. I'll use the integer. Maybe this is an opportunity to perfect and practice the form/structure/syntax  of my code.

Edited by LAURENT*

Share this post


Link to post
Share on other sites

As mentioned by frob, unless the language you are working in does enums strange.

 

That said it appears you are working with Java because you mentioned Andoid then the advise if probably good in that your should avoid them for a different solution. 

Any other language and the advice would be rubbish as enum normally means int but Java, oh let me count the ways I hate you Java lol

Share this post


Link to post
Share on other sites

Java's definition of an enum is different than most other languages.  

Think this was the best point! Languages can have a massive swing in how individual methods are rated. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement