Originally posted by Johnny Klarik:
I could define a class that resides in the directory structure java/util/ArrayList/Foo.java
Originally posted by adam lui:
first what do you wanna do?
if you want to use the ArrayList class, you get the nearly right statement, except it should be like this..
import java.util.ArrayList;
if you want to put your foo.class into the java.util.ArrayList, i dont think that is practically not possible - the compile will complain...
The dude abides
SCJP 5.0
Originally posted by Kelvin Lim:
Yes, of course it'll work if you actually create your own java.util.ArrayList package. (note that Java will automatically deconflict package names and class names.) But the point that K&B makes is that you can't apply the .* suffix to a classname in a non-static import statment. You're not supposed to add your own classes or packages to the java.* packages, so that's why they chose that particular class as an example.
But, yes, if you did create a package with the same name as a class, then what you did is perfectly valid syntax. (note however that this means you're violating the naming convention of keeping package names all lowercase.)
The dude abides
The members of a package are subpackages and all the top level (�7.6) class (�8) and top level interface (�9) types declared in all the compilation units (�7.3) of the package.
...
A package may not contain two members of the same name, or a compile-time error results.
Here are some examples:
* Because the package java.awt has a subpackage image, it cannot (and does not) contain a declaration of a class or interface type named image.
SCJP 5.0