Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>List is a generic <strong>interface</strong>, and the same interface regardless of the generic type. As such, all implementors are required to redefine all methods in it. As far as being able to add null into an "unbounded" list, it's not as much a matter of methods as much as a requisiste of respecting the interface:</p> <p>the unbound generic wildcard allows a reference to a List (or other generic class) to be passed around to methods without requiring a compile-time knowledge of the specific type it will contain. However, the contract of the generic must still be respected. This poses no big problem for read operations, since whatever is in the List, it will always (also) be a <em>java.lang.Object</em>. On the other hand, insert operations are almost impossible, since lacking informations about the accepted types, no type can be accepted - e.g. a <em>List</em> can only accept strings, but an <em>Object</em> could be anything else - a Number for example, and thus cannot be accepted safely.</p> <p><strong>Null</strong> works safely since (assuming the List accept null values), it will be the only value that's always valid to be put inside the list (a <strong>null</strong> can be cast to any valid type).</p> <p><strong>Edit</strong>: just since i noticed i didn't actually answer your question: yes, the <code>&lt;?&gt;</code> wildcard (and the extended forms as well <code>&lt;? extends X&gt;</code> and <code>&lt;? super X&gt;</code> are only valid when defining references, and cannot be used in generic instantiation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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