1 Reply Latest reply on May 26, 2009 7:54 PM by Norman Richards

    using import static in Seam

    Arbi Sookazian Master

      I've noticed some of the Seam distro example code uses import static for ScopeType enum values like the following:


      package org.jboss.seam.example.seambay;
      
      import static org.jboss.seam.ScopeType.EVENT;
      
      ...
      
      @Name("memberAction")
      @Scope(EVENT)
      public class MemberAction implements Serializable
      {
         ...   
      }



      So is this just a matter of coding style and possible convenience to do the static import on ScopeType.EVENT in this case?  Usually I would just use the following:


      @Scope(ScopeType.EVENT)



      instead.  How much added value is there in doing the static import when the imported value/variable/etc. is only referenced once in the class?


      http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html:



      So when should you use static import? Very sparingly! Only use it when you'd otherwise be tempted to declare local copies of constants, or to abuse inheritance (the Constant Interface Antipattern). In other words, use it when you require frequent access to static members from one or two classes. If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from. Importing all of the static members from a class can be particularly harmful to readability; if you need only one or two members, import them individually. Used appropriately, static import can make your program more readable, by removing the boilerplate of repetition of class names.

      So in this specific context of a Seam app and enums, is it considered good or bad practice to do the static import?