so I tried to find the answer, but for this error message I find the appropriate answers to my problem.
There he is. Why is this code:
Case 1)
public class A {
    private final String A;
    private final String B;
    private final String C = A + B;
    public A(String A, String B) {
        this.A = A;
        this.B = B;
    }
}
for the string, private final String C = A + B;he talks about these errors:
java: variable A might not have been initialized
java: variable B might not have been initialized
But it works like a charm:
Case 2)
public class K {
    private final String K;
    private final String L;
    private final String M = kPlusL();
    public K(final String K, final String L) {
        this.K = K;
        this.L = L;
    }
    private String kPlusL() {
        return K + L;
    }
}
Or it works like a charm:
Case 3)
public class O {
    protected final String O;
    protected final String P;
    public O(final String O, final String P) {
        this.O = O;
        this.P = P;
    }
}
public class Q extends O {
    private final String Q = O + P;
    Q (final String O, final String P) {
        super(O, P);
    }
}
Can someone explain to me why, please? I am using IntelliJ IDEA and Java 1.8.0_151.
All three cases do the same (puts two lines together), but each does it directly, and the second and third are "indirect".
source
share