Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • I came up with this import static Templates.NewDeviceDetailsConsts.*. I will use this and use the Consts directly. Is this approach better or should I go with enums? Commented Jun 4, 2016 at 19:55
  • The problem with static imports is that you pollute the namespace of your classes. Imagine you use them in lot of classes and let us assume the classes are more than a couple of lines long, then if you encounter a constant AAA in the code you do not directly see where it comes from. If you use them in class hierarchy they can cause error you might not see easily. As for me, I don't see any reason why I have to use static constants instead of enums. Enums are very powerful too. Commented Jun 4, 2016 at 20:19
  • If you are still looking for more information as to which variant to use here you will find some very good explanations why you should consider using enums. Not only the accepted answer but also others have very good explanations. Commented Jun 4, 2016 at 20:48