JDK5.0 new Features-static import

Source: Internet
Author: User

Static import (Know)
Format: import static package name. Class Name. Method name (attribute name);

You can use this static member in a class without the class name. Simply write the method name or the property name as you like.

Static Import Disadvantages:
1. Code readability decreased.
2. Due to the repetition of the method name, static import will error in some specific cases.

---------------------------

 PackageCn.itcast.staticdemo;Importjava.util.Arrays;Importorg.junit.Test;Import Staticjava.util.arrays.*;Import Staticjava.lang.math.*;//Static Import//Static Import Public classDemo {@Test Public voidFun () {//Double d = math.random ();//get a random number between 0-1 contains 0 does not contain 1        DoubleD =random ();        System.out.println (d);    System.out.println (PI); } @Test Public voidfun1 () {int[] arr = {1, 2, 3 }; String s=arrays.tostring (arr); //String s = toString (arr);//repeat with the ToString method in the object class. System.out.println (s); }}

JDK5.0 new Features-static import

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.