Static import of Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.