样式 1
public interface Constants{
String FOO = "foo",
BAR = "bar",
... ;
}
STYLE 2
public interface Constants{
String FOO = "foo";
String BAR = "bar";
...
}
我曾经在单个接口中声明所有的常量。我遵循样式1,因为它更易读。我想知道除了可读性之外,这两种风格是否有任何区别。这两种风格是否存在与性能相关的问题?
注意:我从未实现过Constant接口,而是像Constants.FOO这样访问那些常量。
示例:
public class Main{
public static void main(String[] args){
...
System.out.println(Constants.FOO);
...
}
}
哪个更好,为什么呢?