Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using import * statements use more memory than stricter imports?  RSS feed

 
Doug Nichols
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At work, they mandate that we use very specific import statements, instead of ones with an asterick at the end. Eg:

java.util.Vector
instead of
java.util.*

Why? Does the compiler use more memory to execute the application if you include the '*'?
 
Leonardo Pjetri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
becouse you are including all the files after * not just the one you want
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?WildCardVsSpecificImports
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally try to avoid the "global" imports (*) because they can sometimes hide problems. For example, if you import an entire package that contains a class whose name duplicates one you already have, you might not realize (at first) which class is actually in use. This can lead to some weird runtime behaviors at times. You'll figure out the problem eventually, but it's better not to have the problem in the first place.

FYI, Eclipse's "Organize Imports" command greatly simplifies import management. Puts in the imports you need & removes the ones you don't. When it encounters an ambiguous class name, it lets you know up front. No guesswork involved.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Doug Nichols:
At work, they mandate that we use very specific import statements, instead of ones with an asterick at the end. Eg:

java.util.Vector
instead of
java.util.*

Why? Does the compiler use more memory to execute the application if you include the '*'?


Import statements do not use any memory at runtime. I also doubt that there is an significant difference at compile time. The "specific import" statement is considered more clear since it is obvious which classes you are using. It also can help avoid other issues when there are duplicate class names in different packages.

Layne
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Along with the above comments, I would add that it helps make your code be somewhat more self-documenting, which is always a good thing. Not as much as using descriptive method/variable names but it helps.
[ January 10, 2006: Message edited by: Rusty Shackleford ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!