1

What is the difference between @IntDef and Enum? I can create int fields in Enum, so it will be also an instance with primitive data constants. Why Google recommends using @IntDef, can somebody explain? Does anyone of this two store its data in some specific way?

Thanks in advance.

Nazarii Moshenskiy
  • 1,802
  • 2
  • 16
  • 35
  • https://stackoverflow.com/questions/32360537/when-is-it-good-to-use-enum-in-android#comment52594240_32360537 – CommonsWare Dec 26 '18 at 16:56
  • 1
    @CommonsWare yes, saw lots of comments that it's premature optimization but I'm interested in the difference between `enum` and `@IntDef`. Trying to understand why Google recommends this and how does it work internally. – Nazarii Moshenskiy Dec 26 '18 at 17:01
  • 1
    `@IntDef` is just an annotation, used by build tools to help make sure that you use `int` values with the proper meanings in the proper places. `enum` is an actual language construct in Java and Kotlin. The difference between `int` and `enum` is covered in advanced Java texts, plus a variety of of online resources, such as [this SO question](https://stackoverflow.com/q/9254637/115145). – CommonsWare Dec 26 '18 at 17:11

0 Answers0