楼上别误导别人
final 修饰符可以与static 同时使用的;
见java源码如下
[AppleScript] 纯文本查看 复制代码
/**
* The "standard" error output stream. This stream is already
* open and ready to accept output data.
* <p>
* Typically this stream corresponds to display output or another
* output destination specified by the host environment or user. By
* convention, this output stream is used to display error messages
* or other information that should come to the immediate attention
* of a user even if the principal output stream, the value of the
* variable <code>out</code>, has been redirected to a file or other
* destination that is typically not continuously monitored.
*/
public final static PrintStream err = null;
final 和static 同时使用
此处是用于声明一个全局的不可更改的常量;
让使用者可以通过类名.来调用,
并且避免使用者通过某些方式对其更改,导致程序的后续运行出错.
有时候有些常量在当前类中使用频率较高;
或者是其调用者的使用频率较高,用final static 声明一个常量,可以编写代码的效率;
如数学中的PI;
若是,将其使用一次,便输入一次,是十分麻烦的,
[AppleScript] 纯文本查看 复制代码
/**
* The {@code double} value that is closer than any other to
* <i>pi</i>, the ratio of the circumference of a circle to its
* diameter.
*/
public static final double PI = 3.14159265358979323846;
|