Java Import all classes from another package [closed]

-4

I have 2 packages, I would like to import package B into all classes of package A.

    
asked by anonymous 04.07.2017 / 18:57

1 answer

2
  

I would like to import into package B all classes of package A

It is impossible to import classes into another package. This does not exist.

It is only possible to import classes from a package into a class.

To import all classes from package A to class B, you can do two ways: explicit import or import implicit .

Explicit Import

Explicit import is used when you import exactly that class from some package. For example:

import br.com.teste.controller.ClienteController;

Being ClienteController is a class.

Implicit Import

Implicit import is when you import all the classes of some package into your class without declaring the import one by one.

Understand: You can import all classes of a package into your class using explicit import as well. It may just be a little painful depending on the size of the package.

To perform an implicit import, do the following:

import br.com.teste.controller.*;

In this way all the br.com.teste.controller package classes will be imported into your class.

Concrete Example

Let's assume that the br.com.teste.controller package is made up of classes:

  • ClienteController
  • UsuarioController
  • ProdutoController
  • PedidoController

Explicit Import :

import br.com.teste.controller.ClienteController;
import br.com.teste.controller.UsuarioController;
import br.com.teste.controller.ProdutoController;
import br.com.teste.controller.PedidoController;

Implicit import :

import br.com.teste.controller.*;
    
04.07.2017 / 19:46