In one of our Java projects I found the following code for starting a thread:
new WorkerThread(socket).start();
Now according to operator precedence in Java this is wrong! It should be instead:
(new WorkerThread(socket)).start();
Now my question:
Why is it still working? Are there any dangers?
Just for reference, WorkerThread is implemented pretty straightforward:
private class WorkerThread extends Thread
{
private Socket socket;
public WorkerThread(Socket socket)
{
super();
this.socket = socket;
}
@Override
public void run()
{
try
{
/* do stuff... */
}
catch (IOException e)
{
}
finally
{
socket.close();
}
}
}