This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about import statements...

 
Matt O'Toole
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's something I don't understand about import statements, or maybe I'm just missing something really obvious. Why would a class have to be imported specifically, if the * has already been used with its parent package? For example, why would I have to say:
import java.awt.*;
import java.awt.event.*;
Shouldn't event already be imported with the first line, because of the *? I get compiler effors complaining of this problem, and it's easy enough to just fix them with another, more specific import statement. But I never know from the outset whether I've done my imports correctly, and there seems to be no rhyme or reason to how this works. How does it work? What's going on here?
BTW, it's really cool how IntelliJ Idea generates import statements for you...
...but I still wanna know!
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to think of packages as folders (directories) in a tree structure. That is really all they are and as silly as it may seem, you do have to import both java.awt.* and java.awt.event.* because the import only imports the classes in that directory and does not traverse the sub-directories.
Hope this clears it up
 
Matt O'Toole
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha! Thanks! -Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic