关于字段的私有静态最终关键字的快速Java问题 [英] Quick Java question about private static final keywords for fields

查看:177
本文介绍了关于字段的私有静态最终关键字的快速Java问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在声明一个字段:

private static final String filename = "filename.txt";

首先,私有静态最终问题?如果没有,是否有标准接受的序列或约定?

First, does the order of private static final matter? If not, is there a standard accepted sequence or convention?

其次,我的应用程序中的文件名是固定的。这是最好的存储它的价值吗?

Second, the filename in my application is fixed. Is this the best was to store its value?

推荐答案

我使用 Checkstyle ,如果声明与您指定的声明的顺序不同,则会引发警告,引用Java语言规范(JLS)。例如,

I use Checkstyle with Eclipse, which results in a warning if the declaration is in a different order to the one you've specified, citing the Java Language Specification (JLS). For example,

private final static String filename = "filename.txt";

结果

'static' modifier out of order with the JLS suggestions.

他们有此页面列出了他们期望的顺序,但是按照该页面上的链接到 JLS 我看不到任何支持建议订单断言的内容。

They have this page which lists the order they expect, though following the links on that page through to the JLS I can't see anything to back up their assertion of a suggested order.

话虽如此,他们建议的顺序似乎与我见过的大多数代码中的顺序相对应,所以它似乎与任何采用的约定一样好。

Having said that, the order they suggest seems to correspond to the order in most of the code I've seen, so it seems as good a convention as any to adopt.

这篇关于关于字段的私有静态最终关键字的快速Java问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆