0

how do i define multilevel packages in java

package foo;

one level package

package foo[.1oo[.2oo]];

doesn't work.

offex
  • 1,875
  • 5
  • 17
  • 27
user581734
  • 1,219
  • 3
  • 15
  • 24
  • 3
    Where have you heard of "multilevel packages"? These don't exist. A package is just a namespace for classes, to avoid naming conflicts across the thousands of classes existing. You should explain us what you want to do. – JB Nizet Mar 01 '11 at 15:16

1 Answers1

8

It doesn't work because package names must start with a letter. This works:

package foo.bar.baz;

N.B. package names aren't hierarchical or nested in the way that they might look. A package name is simply an identifier for a namespace. That means that package foo.bar.baz is not truly a subpackage of package foo.bar.

See also:

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Thanks, the 2nd link there helped alot – Adam Jun 18 '11 at 03:07
  • "package names aren't hierarchical or nested in the way that they might look. […] `package foo.bar.baz` is not truly a subpackage of `package foo.bar`". Not true; subpackages are defined in the JLS as a hierarchical naming structure. Though the only thing the language does with subpackages is prevent them from having the same name as a top-level type in that package (e.g. package `com.example.A` and class `com.example.A` cannot both exist). https://stackoverflow.com/a/64018076/1108305 – M. Justin May 30 '23 at 20:47