Why a variable is seen in the loop and is not seen outside the loop?
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-03-18T14:56:57Z
Indexed on
2010/03/18
15:01 UTC
Read the original article
Hit count: 277
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.
© Stack Overflow or respective owner