[ https://issues.apache.org/jira/browse/WICKET-2137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12679018#action_12679018 ]
omichallat edited comment on WICKET-2137 at 3/4/09 5:02 PM: ------------------------------------------------------------------- Brill, James is right, the new signature will accept an IModel<List<Integer>>. This takes care of not pushing the wildcard onto the caller. As for the "read-only" problem, it can easily be solved with a private helper method that captures the wildcard. Here is another example: // Simulates the DropDownChoice with the change suggested by James static class DropDownChoiceWidened<T> { // Just an artifact to simulate getModelObject private IModel<? extends List<? extends T>> model; // The new constructor with widened type public DropDownChoiceWidened(String id, IModel<? extends List<? extends T>> model) { this.model = model; } // The getModelObject inherited from FormComponent would have this signature: public List<? extends T> getModelObject() { return this.model.getObject(); } } // intModel is the same as in my previous example (an IModel<List<Integer>>) // Now the constructor invocation compiles: new DropDownChoiceWidened<Number>("id", intModel) { // Should the component need to mutate the list: public void someMethodThatNeedsToRemoveElements() { safeRemove(this.getModelObject(), 1); } // Private helper that captures the wildcard private <T extends Number> void safeRemove(List<T> list, int index) { // List<T> is not read-only list.remove(index); } }; My vote changes in favor of James' widened wildcard. was (Author: omichallat): Brill, James is right, the new signature will accept an IModel<List<Integer>>. This takes care of not pushing the wildcard onto the caller. As for the "read-only" problem, it can easily be solved with a private helper method that captures the wildcard. Here is another example: // Simulates the DropDownChoice with the change suggested by James static class DropDownChoiceWidened<T> { // Just an artifact to simulate getModelObject private IModel<? extends List<? extends T>> model; // The new constructor with widened type public DropDownChoiceWidened(String id, IModel<? extends List<? extends T>> model) { this.model = model; } // The getModelObject inherited from FormComponent would have this signature: public List<? extends T> getModelObject() { return this.model.getObject(); } } // intModel is the same as in my previous example (an IModel<List<Integer>>) // Now the constructor invocation compiles: new DropDownChoiceWidened<Number>("id", intModel) { // Should the component need to mutate the list: public void someMethodThatNeedsToRemoveElements() { safeRemove(this.getModelObject(), 1); } // Private helper that captures the wildcard private <T extends Number> void safeRemove(List<T> list, int index) { // List<T> is not read-only list.remove(index); } }; Thanks to James' suggestion, I now agree with a wildcard type. > Remove ? extends from constructor of DropDownChoice > --------------------------------------------------- > > Key: WICKET-2137 > URL: https://issues.apache.org/jira/browse/WICKET-2137 > Project: Wicket > Issue Type: Improvement > Components: wicket > Affects Versions: 1.4-RC3 > Environment: 1.4-SNAPSHOT as of 2009-01-28 > Reporter: Brill Pappin > Attachments: TestGenerics.java > > > DropDownChoice has a generics definition of List<? extends T> in its > constructor. > This causes trouble with existing models that may be used in a DropDownChoice > and is not consistant with ListView which uses <List<T>>. > Change DropDownChoice to match the other list type components so that their > models can be used across components. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.