File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Static imports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static imports" Watch "Static imports" New topic
Author

Static imports

Kalyan Anand
Ranch Hand

Joined: Feb 07, 2007
Posts: 194
What is the consensus on the use of static imports in code. I s it a sin ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

please read this
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
Why should using a java language feature be a sin?

Personally, I don't use import static with a '*', but import each class or method explicitly.

Regards,
Thomas


SCJP 5.0, SCJD in progress
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

The article that seetharaman venkatasamy gives a link to explains the following:

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
Consider Paul's rocket mass heater.
 
subject: Static imports
 
Similar Threads
Implemetinng the interface with all static final variables
static imports
usage and advantage on static imports
Java 5.0 static import same members collision from different classes
IMPORTS Doubt