Why a variable is seen in the loop and is not seen outside the loop?
- by Roman
I have the following code:
String serviceType;
ServiceBrowser tmpBrowser;
for (String playerName: players) {
serviceType = "_" + playerName + "._tcp";
tmpBrowser = BrowsersGenerator.getBrowser(serviceType);
tmpBrowser.browse();
System.out.println(tmpBrowser.getStatus());
}
System.out.println(tmpBrowser.getStatus());
The compiler complains about the last line. It writes "variable tmpBrowser might not been initialized". If I comment the last line the compile does not complain.