2

I saw the video(https://www.youtube.com/watch?v=Hzs6OBcvNQE) posted from google about price of enum and I'm convinced that enum cost more and has performance issue.

However, what about when I need to contain multiple information in an enum? Do I have to create intdef and stringdef to map the message?

Ie.

public enum Error{
    NETWORK(1, "Network error!"),
    STACK_OVER_FLOW(2, "Stack over flow error!");
    final int mValue;
    final String mMessage;

    Error(int value, String message){
        mValue = value;
        mMessage = message;
    }

    public void getMessage(){
        return mMessage;
    }

    public void getValue(){
        return mValue
    }
}
Rubin Yoo
  • 2,674
  • 2
  • 24
  • 32
  • http://stackoverflow.com/questions/4709175/what-are-enums-and-why-are-they-useful – Zarwan Sep 02 '15 at 18:26
  • 4
    "I'm convinced that enum cost more and has performance issue" -- few Java and Android experts agree with the presenter on that video. See [Jake Wharton](https://twitter.com/JakeWharton/status/638447874515275776), [Bob Lee](https://twitter.com/crazybob/status/636959556539539457), and [Joshua Bloch](https://twitter.com/joshbloch/status/628663950389841920), for example. – CommonsWare Sep 02 '15 at 18:39
  • 5
    If the bottleneck of your app is enums, you have a damn good app. – SqueezyMo Sep 02 '15 at 19:07

1 Answers1

0

It is true that enums have that memory footprint, but just if are heavily using them, or sub using them, like comparisions or else, but if you're using such functionality like the one in your code, it's more than justified to work with them, in case you want to totally avoid enums, you can change this to a class.

Myke Dev
  • 180
  • 9