The modifier finalforbids changing the variable after setting it. Kevin gives an excellent explanation of why you cannot use it in this context.
For the construction of your choice, you need to enter the field of the parent class and set it via run():
class MyClass {
Process tool_proc = null;
void myFunction() {
final String run_tool ="cmd.exe /C pelda.exe";
Runnable doRun = new Runnable() {
public void run() {
try {
tool_proc = Runtime.getRuntime().exec(run_tool);
}
catch (IOException e) {
e.printStackTrace();
}
}
};
Thread th = new Thread(doRun);
th.start();
InputStream toolstr = tool_proc.getInputStream();
}
}
, tool_proc null , !
NullPointerException s!
, , . , . , StreamGobbler ( . 4).