• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Package Access

 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there:

A package is used to store related classes. And a package is just like a folder.
In eclipse, I create a package "SimpleGUI" in src directory, and create another package "SimpleGUI.model". Actually, "SimpleGUI.model" is a folder "model" in .../src/SimpleGUI

So I should be able to regard everything in folder "model" as something that is also in folder "SimpleGUI". So I should also be able to regard a class in package "SimpleGUI.model" as a class in package "SimpleGUI". (Is this true?)

However, , in package "SimpleGUI", when I try to use a class that is defined in package "SimpleGUI.model", I have to import SimpleGUI.model.classname
Otherwise, type will not be able to be resolved.

Why is that? If it is true that a class in package "SimpleGUI.model" is also a class in package "SimpleGUI" (The logic is: package is folder, so "in sub-folder" means "a part of folder" means "a part of package"), "import" shouldn't be necessary.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. If you import a package then (e.g. java.util.*) then the subpackages are not imported. You must import them separately (e.g. import java.util.concurrent.*).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Java conventions say that package names should be all lowercase.
 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'll just keep that in mind.
Thanks, guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic