so I've tried to search for answer, but for this error message I'm founding irelevant answers to my problem.
Here it is. Why 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 line private final String C = A + B; it says these errors:
java: variable A might not have been initialized java: variable B might not have been initialized But this works like a charm:
Case2)
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 also this 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 somebody explain me why please? I'm using IntelliJ IDEA and Java 1.8.0_151.
All three cases are doing exact same thing (puts two Strings together), but one is doing it directly and second and third "indirectly".