Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at <a href="http://download.oracle.com/javase/6/docs/api/java/util/List.html" rel="nofollow">the JavaDocs for List</a>.</p> <p>A lot of them have lines like this, showing that they're from the <code>Collection</code> interface:</p> <blockquote> <p>Specified by:</p> <pre><code>size in interface Collection&lt;E&gt; </code></pre> </blockquote> <p>The ones with no "specified by" section are:</p> <pre><code>E get(int index) E set(int index, E element) void add(int index, E element) E remove(int index) int indexOf(Object o) int lastIndexOf(Object o) ListIterator&lt;E&gt; listIterator() ListIterator&lt;E&gt; listIterator(int index) List&lt;E&gt; subList(int fromIndex, int toIndex) </code></pre> <p>Where <code>E</code> is the <code>Type</code> specified in <code>List&lt;Type&gt;</code>.</p> <p>Basically, it's a bunch of things related to indexes -- because not all <code>Collections</code> have an index, or an order at all for that matter, and a couple related to special iterators, and <code>subList</code>.</p> <p>The advantage to using <code>Collection</code> in method signatures is that you don't force your users to use one kind of collection (some users can use a <code>Set</code>, some can use a <code>List</code>, etc.). This only makes sense if you don't need the methods that `List gives you.</p> <p>In this example, I'm not using any <code>List</code>-specific methods:</p> <pre><code>/** * Simple example, adds "1" to the Collection */ public static void addOne(Collection in) { in.add(1); } </code></pre> <p>There's no reason to force users of this method to only pass it a list, because the only method we're calling on it (<code>add</code>) is available in all <code>Collection</code>s.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload