Brent Allard
Brent Allard

Reputation: 396

Java Wildcard Import Statements

The top of my javaFX programs will usually look something like this:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;

I was wondering if there's any way to simply import everything from javaFX using a statement like import javafx.*; or something similar. Otherwise, is there an easy way to find the required import statement for any new piece of the api that I learn?

Upvotes: 1

Views: 8080

Answers (2)

Patrick
Patrick

Reputation: 66

As stated before, it is very bad practice import more then you actually need. And as a programming teacher I would personally mark a project down if it would do blanket imports...

Upvotes: 2

MikeJ
MikeJ

Reputation: 2437

Generally its regarded as bad practice to bring in more than you need using wilcards. You can inadvertently use the wrong class. Classes are cleaner if you explicitly import what you need. Regarding finding the import, most IDE's will assist you by suggesting a list of possible imports.

Upvotes: 4

Related Questions