Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import package.*

 
James Inge
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if there are any performance or class 'bloat' issues associated with using the import of package.* versus including only the classes which you are using?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that importing more classes than you need has no effect on run-time performance.
The import statement affects which classes should be made available by class name only, so that they may be referenced in the source without their package prefix, during compilation. However, this does not affect which files get loaded, or how much memory gets used when running.
I do not know whether the compiler goes slower, faster or about the same speed if import packagexxx.* is used, compared to individual imports.
However, for clarity and to avoid namespace clashes (class with same name in two packages -> confusion), I think that developers should always explicitly import individual classes, even if it makes for a rather long prolog to the source file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic