Is it bad practice to create new objects without storing them?
<p>I've seen objects created in Java code without storing a reference to the object.  For example, in an eclipse plugin I've seen a SWT Shell created like so:</p>

<pre><code>new Shell();
</code></pre>

<p>This new Shell object is not stored in a variable, but will remain referenced until the window is disposed which [I believe?] happens by default when the window is closed.</p>

<p>Is it bad practice to create objects like this without storing a reference to them? Or was the library poorly designed? What if I don't have need of a reference, but only want the "side effects" of the object? Should I store a reference anyways?</p>

<p>UPDATE:</p>

<p>Admitedly, my above example is poor.  While I have seen UI elements created like this, creating a SWT Shell like this would probably be pointless because you need to call the open method on the Shell instance.  There are <a href="http://stackoverflow.com/a/8841716/565879">better examples provided by aix</a> such as the following from the <a href="http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html" rel="nofollow">Java concurrency tutorial</a>:</p>

<pre><code>(new HelloThread()).start();
</code></pre>

<p>This practice is seen in many contexts, so the questions remains. Is it good practice?</p>
