How can I import multiple classes in Java with fewer import fewer import statements?

1.1k Views Asked by At

I am quite new to using packages in Java and I would like to know if there is an easier way to import classes with fewer import statements.

I am using Processing and I have started using Box2D for Processing to create some games.

In order to use the library, I have to add the following to my sketch:

import shiffman.box2d.*;

import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.joints.*;

To simplify the imports, I have tried:

import shiffman.box2d.*;

import org.jbox2d.*;

However, when I define a body using BodyDef, I get an error saying that BodyDef is not defined.

Processing error

It seems that the error is also mentioning that org.jbox2d.* is not a package...

Is there a way to have fewer import statements? PDE doesn't seem to include those as well...

Thanks in advance!

1

There are 1 best solutions below

0
George On

You can only import Types and static methods in Java.

A similar question is actually answered in: Importing packages in Java.