是的,无论它们的初始值如何,它们都是等价的。
下面是一些测试代码来演示:
public class TestClass
{
private static boolean readAllFiles = false,readAllDirs = true;
public static void main(String[] args)
{
//these two would result in COMPILE error if both vars were not static
System.out.println("readAllFiles: " + readAllFiles);
System.out.println("readAllDirs: " + readAllDirs);
}
}
public final class TestClass2
{
public static void main(String[] args)
{
//these two DO result in COMPILE error, because both vars are private
System.out.println("TestClass.readAllFiles: " + TestClass.readAllFiles);
System.out.println("TestClass.readAllDirs: " + TestClass.readAllDirs);
}
}