Concept:
Static import is a new feature introduced by JDK5, which is directly visible in the current class using static import of static and static methods of imported classes.
Static members do not have to give their class names any more, and there is no difference between calling them and calling their own methods.
How to use:
Add the static keyword after the import keyword.
Advantages:
Easy to use
Disadvantages:
The readability of the program becomes worse
Instance:
Package zzy.studio.javase.news;/** * @author Zhoujiaoshou */public class Staticmemberprovider {public static final int MAX = 999999999;public static final int MIN = 1;}
/** * Demo static import */package zzy.studio.javase.news;import static zzy.studio.javase.news.staticmemberprovider.max;//can be used * Introduce all static members of the class into/import static zzy.studio.javase.news.staticmemberprovider.*;/** * @author Zhoujiaoshou */public class Staticimport {/** * @param args */public static void main (string[] args) {//No way to get maximum value using static import/*int max = Staticmemberprov Ider. MAX; SYSTEM.OUT.PRINTLN ("Maximum value cannot be greater than:" + max); *///uses static import to get the maximum value System.out.println ("Maximum value cannot be greater than:" + max);}}
Static import of Java