📜  final 私有 vs 私有 final - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:26.984000             🧑  作者: Mango

代码示例1
There is no difference between private final and final private.

public class TestClass {

    private final String i1;
    final private String i2;
    private final String i3 = "test"; // ok
    private final String i4; // not ok, never initialized

    TestClass() {
        i1 = "test1"; // ok
        i2 = "test2"; // ok
        i3 = "test3"; // not ok, overrides already set value
    }

    void mod() {
        i1 = "test0"; // not ok, can't edit final i1
    }
}