Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java package in package?

I'm using eclipse 3.8 indigo and I don't know why, when I'm creating a new package the destination of the new package goes outside. I want to create new packages within a package: package in package. I tried to copy / paste the newly created package or to move, but it just copies.

For example, I want to create different packages: dialogs, views, tables, etc. in my main source package. For example:

com.new.application // this is the the main package created by wizard com.new.application.view // package that contains all views. 
like image 593
Reteras Remus Avatar asked Dec 10 '12 21:12

Reteras Remus


People also ask

Can you put a package in a package Java?

There is no concept of package with in package. Each package is separate namespace.

Does Java have subpackages?

The package java has subpackages awt , applet , io , lang , net , and util , but no compilation units. The package java. awt has a subpackage named image , as well as a number of compilation units containing declarations of class and interface types.


2 Answers

In reality there is no such thing as a sub-package in Java - each package is a completely separate entity, with the names being seemingly hierarchical only for convenience. For example, items with default visibility are not visible in sub-packages, despite what one might expect.

If your problem has more to do with presentation and aesthetics than substance, then perhaps what you are looking for is the hierarchical package presentation setting in the Eclipse Package Explorer: click on the little downward triangle/arrow at the top right of the package explorer and select "Hierarchical" in the "Package presentation" submenu:

enter image description here

This is a global setting and will affect all your opened/un-opened projects.

like image 178
thkala Avatar answered Oct 02 '22 13:10

thkala


There is no concept of package with in package. Each package is separate namespace. I think if you go to folder view instead of package view, there you may see one under another.

like image 44
kosa Avatar answered Oct 02 '22 14:10

kosa