0

Possible Duplicate:
Performance difference between a wild card import and the required class import
Implications importing java packages with wildcard

My QA leader set up a checkstyle rule that java.util.* can not appear in the source code, use java.util.XXX instead. For example , you can only write:

import java.util.Date;
import java.util.List;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
// ... may be thousands import statement here 

but not allowed:

import java.util.*;

If anyone do not follow the rule, QA team will not do the integration test. He told me that the style of import java.util.XXX is more clear than import java.util.*, and makes JVM run faster. Is it true ?

Community
  • 1
  • 1
爱国者
  • 4,298
  • 9
  • 47
  • 66
  • 2
    It is slightly clearer but it **definitely** does **not** make the JVM run faster (imports are resolved at compile time, not at runtime). –  Feb 05 '13 at 08:04
  • 4
    your question mark is stunning... – Juvanis Feb 05 '13 at 08:04
  • 1
    *"makes JVM run faster"* That part is incorrect. It affects only the compiler. By run-time, the classes are individually and explicitly identified. – Andrew Thompson Feb 05 '13 at 08:05

1 Answers1

3

If you include java.util.*, you're including all of the classes in the java.util package.

When including java.util.classname, you're only including the specified class in the java.util package.

Using java.util.* will not slow down the JVM because imports are handled at compile time, not runtime.

Zach Latta
  • 3,251
  • 5
  • 26
  • 40