package com.mypackage;
import java.util.List;
import java.util.Map;
public class InitializationDemo {
public static void main(String[] args) {
List<String> a, b = null;
List<String> c = null, d = null;
Map<String, String> e, f = null;
Map<String, String> g = null, h = null;
if(c == null){ //line $38: Works no compilation error
// Do Something here
}
if(a == null) { //line #40: compilation error
// Do Something here
}
if(e == null) { //line #44: compilation error
// Do Something here
}
if(g == null) { //line #46 Works no compilation error
// Do Something here
}
}
}
Get the "The local variable a may not have been initialised." compilation error at line #40 and line #44:
I am trying to understand under the wood how does it work so that line #38 and #46 does not signal a compilation error however #40 and #44 signals compilation error.
=sign. It does not apply to any other variables declared in the same statement, either before or after.