• Post Reply Bookmark Topic Watch Topic
  • New Topic

static import of enum with .* syntax  RSS feed

 
Juan Rolando Prieur-Reza
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am interested in your advanced opinions on this question...
Proposed best practice:



I find that this is consistent with Sun's and other literature.
e.g. http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html

Thanks in advance for your well considered recommendations on this question.
[ August 29, 2008: Message edited by: juan prieur ]
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I my humble opinion, you should use as few static imports as possible.

If you find that you want to do a big static import of an enum, ask yourself: should this enum in fact be a part of my class?

If you say "no", then ask: Could the method(s) using all the enums be a part of the enum instead? Very often I find that the answer is "yes, it could" and then I move the logic (mostly checking if a value is equals any of the enum values) to the enum class.

If you still feel the need to import, try to only import the parts you REALY need.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!