Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Are Long Package Names Atomic?

 
Kevin Simonson
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With directory structure:

Life
|---source
| |---UseLife1.java
| |---UseLife2.java
| |---animal
| | |---mammal
| | | |---Whale.java
| | | `---Dog.java
| | |---reptile
| | | |---Snake.java
| | | `---Lizard.java
| | `---bird
| | |---Ostrich.java
| | `---Canary.java
| `---plant
| |---Bush.java
| `---Flower.java
`---target

and file "UseLife1.java" written like so:



I can change to directory "Life\source" and type in:

javac -d ..\target UseLife1.java

and that command will compile all the source code and put class files under "Life\target" (including the class file for class <UseLife1>).

But if file "UseLife2.java" is written like so:



and I, once again from directory "Life\source", type in:

javac -d ..\target UseLife2.java

I get error message:

UseLife2.java:2: cannot find symbol
symbol : class reptile
location: package animal
import animal.reptile;
^
UseLife2.java:9: package reptile does not exist
reptile.Snake sn = new reptile.Snake();
^
UseLife2.java:9: package reptile does not exist
reptile.Snake sn = new reptile.Snake();
^
3 errors

This is actually exactly what Sun Certified Programmer for Java 6 Study Guide says should happen, because package names are atomic, and can't be split up like I'm doing here. But why exactly was it decided to make package names atomic like this? Wouldn't it be a handy shorthand to be able to import <animal.reptile> like "UseLife2.java" does and then refer to <reptile.Snake>?

Kevin Simonson
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for why it was decided by the original designers... you'll have to hunt down the original designers and ask them.

To me it seems like your proposal is just another source of ambiguity which would have to have rules written and documented (in the Java Language Specification) and implemented (in compilers) for little or no benefit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic