Class for constants
Uncommon classes need explicit imports
Interface for constants
Static import of Collectors
Example
import java.util.*; import static java.util.Collections.*; public final class StaticImporter { public static void main(String... args){ List<String> things = new ArrayList<>(); things.add("blah"); //This looks like a simple call of a method belonging to this class: List<String> syncThings = synchronizedList(things); //However, it actually resolves to : //List<String> syncThings = Collections.synchronizedList(things); } }
Math.PI
. A static import of java.lang.Math.*
would allow a class to replace Math.PI
with PI
.
More generally, a business application might define a constants class,
and import it statically. This would allow Consts.NEW_LINE
to be referenced as NEW_LINE
, for example.