Extend ArrayList<E> when E is a nested class of the ArrayList itself...is this wrong?
<p>First this IS a Java question so forgive this first C#-related explanation...</p>

<p>I've most recently been using C# where one .cs source file can contain multiple class definitions, example...</p>

<pre><code>// Servers.cs

public class Server {
}

public class ServerList : ArrayList &lt;Server&gt; {
}
</code></pre>

<p>I do the above because it reduces the number of source files and keeps the two classes together.</p>

<p>In Java of course it's one class to one .java file but I had the idea of nesting the Server class as follows...</p>

<pre><code>//Servers.java
public class ServerList extends ArrayList&lt;ServerList.Server&gt; {

    // Edited to make Server class 'static'
    public static class Server implements Serializable {
    }
}
</code></pre>

<p>This builds without compile time errors or warnings but I can't decide if it's right.</p>

<p>The more I look at it, the more I'm happier with it but I'm still worried that it may be considered bad practice or I could run into problems along the line.</p>

<p>So the question...is this OK to do? Sorry if this is a rookie Java question (or even a rookie OOP question - despite using OOP going back to mid 1990s with C++, I'm self taught and have never tried something like this).</p>

<p><strong>EDIT:</strong></p>

<p>Many thanks to all who have provided comments/pointers to this question.</p>

<p>Firstly I've edited my code to make the Server class static - I expect I would have discovered this down the line but it's good to know from the start that I should be approaching it this way.</p>

<p>To expand on things related to other comments...</p>

<p>I have reasons for extending ArrayList rather than using ArrayList (or List) in associated code. I didn't include the code (haven't started yet) but ServerList will encapsulate specific handling of Server objects (including searching on Server-specific fields/members).</p>

<p>Also I'm using ArrayList rather than List as I'll be using an instance of ServerList to bind to an Android Spinner widget (nice and easy with an ArrayAdapter). Sorry I didn't mention Android but my question was (in my mind) specific to Java practice and not really to my choice of classes to achieve what I'm looking to do.</p>

<p>As for extensibility / inheritance etc with respect to other programmers (or myself) using the Server or ServerList classes at a later date, they really are quite specific to the requirements of my current project...not necessarily a good OO approach to class definition I admit (and not usually my approach) but they serve my project best in terms of usability and efficiency.</p>

<p>Thanks again to all.</p>
