J2SE 5.0 instance --- Static introduction

xiaoxiao2021-03-06  19

Static import (static import)

In the past, we need to use a certain type of static variable in other packages, usually in front, the corresponding class name:

Double R = Math.cos (Math.pi * Theta);

Using static introduction, we can remove the previous class name, static introduction statements are like this:

Import static java.lang.math.pi;

It must be noted that this is not the class MATH here, but directly to the defined variable Pi.

Static introduction is not only a static variable, or a static method. Also available *, as shown below:

Import static java.lang.math. *;

Unless we have a large number of frequently constants (or methods), it should be avoided to avoid using static introduction.

转载请注明原文地址:https://www.9cbs.com/read-45829.html

New Post(0)