| Author |
Java Package Access
|
Castor Tack
Ranch Hand
Joined: Dec 06, 2010
Posts: 31
|
|
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.
|
The BEST user interface design I've ever seen? --- A flush toilet.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
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.*).
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56201
|
|
|
And Java conventions say that package names should be all lowercase.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Castor Tack
Ranch Hand
Joined: Dec 06, 2010
Posts: 31
|
|
Okay, I'll just keep that in mind.
Thanks, guys
|
 |
 |
|
|
subject: Java Package Access
|
|
|