Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

final private vs private final

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
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #final #private #private #final
ADD COMMENT
Topic
Name
5+3 =