Is there any way to generalize library imports into Java?

10

I created within a same package called Banco , two classes in Java: ContaSalario and ContaPoupanca . When I'm going to import these two classes into my main class, I do:

import Banco.ContaSalario;    
import Banco.ContaPoupanca;

Is there any way to import all classes from the same package with a single call? For example:

import Banco.all;
    
asked by anonymous 22.09.2015 / 19:00

3 answers

11

It is possible, just do:

import Banco.*

That will import all classes from the Banco package.

Note however that according to JavaBeans, packages must have the first small letter, which is just to differentiate from the classes. So the most appropriate would be to change your package from Banco to banco . Your code would look like this:

import banco.*
    
22.09.2015 / 19:05
5

Yes, do this:

import Banco.*

This form imports all classes in the same package.

Documentation .

    
22.09.2015 / 19:06
5

Import like this:

  

Import Bank. *

Just put. * after the last package you want to import

    
22.09.2015 / 19:05