java - Using wildcard with Lists.partition and nested generic types -
I am using, though I have thought that this is a general question about generic in Java.
I can do this:
Public Zero to some (list & gt; DataBean & gt; ID) {list & lt; List & lt; DataBean & gt; & Gt; Lists = lists. Division (id, MAX_ITEMS);
Why can not I do this?
Public Nullification is an extension of some (list & lt;? Databane & gt; ID) {list & lt; List & lt;? Extension of Databen & gt; & Gt; Lists = lists. Division (id, MAX_ITEMS);
I get the following compilation error:
type mismatch: list & lt; List & lt; Can not convert from capture # 1? Extension of Databen & gt; & Gt; List & lt; List & lt;? Extension of Databen & gt; & Gt;
You need to bind in such a way that it can be completed. Otherwise, ?
is not related to List
for
? id
. You can declare a common method with a named parameter instead of the generic parameter with the wildcard:
public & lt; T increases Databen & gt; Nothing to do (list & lt; T & gt; ID) {list & lt; List & lt; T & gt; & Gt; Lists = lists. Division (id, MAX_ITEMS); }
Comments
Post a Comment