[J2SE 5.0 Topics] [2.6] Static introduction

xiaoxiao2021-03-06  36

The so-called static introduction means that in addition to introducing classes, we now have a choice to introduce a static field of a certain class. Such as:

Import static java.lang.math.pi;

As another example:

Import static java.lang.math. *;

I personally think that this new feature is that there is no obvious advantage in all J2SE 5.0 languages. Unless I think it is necessary, I think I will not use it in my code. The reason is very simple: put too much of other classes of static fields in their own code will clearly reduce the readability of the code, and in the end, I don't know what XXX, what is the quote, where is it? When using a class of static members, write a clear class name and will not give the code too many bloated feelings, but it is clearly marked, I think this is an advantage rather than the shortcomings. Anyway, one more choice is always good.

In addition, in

In the grammatical IMPORT Static, I didn't find how to write a static state of a class.

Method, however, when you introduce by *, this type of static method has been introduced, can be used directly in the code. I don't know if this is interested, or I miss anything.

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

New Post(0)