J2SE 5.0 Instance---static introduction

Source: Internet
Author: User
Tags variables
j2se| static static introduction (static Import)


In the past we were going to use static variables from a class in another package, usually preceded by the corresponding class name:

Double r = Math.Cos (Math.PI * theta);

With static introduction, we can remove the previous class name, and the static introduction of the statement is this:

Import static Java.lang.Math.PI;



It must be noted that this is not the end of class math, but directly to the defined variable pi.

Static introduction is not only to static variables, but also to static methods. You can also use *, as shown in the following:

Import static java.lang.math.*;



Unless we have a high frequency of access to a static constant (or method), we should try to avoid using static introductions.




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.