[
https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588731#action_12588731
]
Johannes Schneider commented on WICKET-1512:
--------------------------------------------
Two things: Why didn't you add the type parameter to
org.apache.wicket.markup.repeater.data.IDataProviderExample.NumberProvider#model?
I think it is missing there.
And here comes the example showing the problem with the missing "? extends".
[code]
public class IDataProviderExample {
public static void main( String[] args ) {
List<Integer> integers = Arrays.asList( 1, 2, 3, 4 );
List<Double> doubles = Arrays.asList( 1.0, 2.0, 3.0, 4.0 );
IDataProvider<Number> myProvider0 = new NumberProvider( integers );
IDataProvider<Number> myProvider1 = new NumberProvider( doubles );
}
private static class NumberProvider implements IDataProvider<Number> {
private final List<? extends Number> backingList;
private NumberProvider( List<? extends Number> backingList ) {
this.backingList = backingList;
}
public Iterator<Number> iterator( int first, int count ) {
return backingList.subList( first, first + count ).iterator();
}
public int size() {
return backingList.size();
}
public IModel<Number> model( Number object ) {
return new Model( object );
}
public void detach() {
}
}
}
[/code]
Explanation: http://blog.cedarsoft.eu/
And yes, I know that it is annoying to type the additional "? extends" all the
time. But remember that a Collection<? extends Foo> is something completely
different than Collection<Foo>.
Many times programmers the programmers avoid using "? extends" to realize later
that they should fix that later (but now it is an incomaptible change).
GlazedList is such an example where the things went completely wrong. They
fixed some issues within the latest snapshots - but not all...
And poorly used Generics are the root of all evil ;-) - at least things are
messed up...
> Widen Generics for Lists/Iteratos
> ---------------------------------
>
> Key: WICKET-1512
> URL: https://issues.apache.org/jira/browse/WICKET-1512
> Project: Wicket
> Issue Type: Bug
> Components: wicket
> Affects Versions: 1.4-M1
> Reporter: Johannes Schneider
> Assignee: Igor Vaynberg
> Fix For: 1.4-M1
>
> Attachments: two_parameters.patch,
> Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of
> org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.