-
1 Jul 2008 5:19 AM #1
Component.getModel() should use wildcard return value
Component.getModel() should use wildcard return value
Shouldn't this method on Component
instead beCode:public ModelData getModel() { return model; }
I have a typed Store<MyModel> and in my tablelistener I want to get a record from the store, like this:Code:public ? extends ModelData getModel() { return model; }
But this fails since the the getRecord expects a MyModel instance, so a cast is needed:Code:Record record = store.getRecord(item.getModel()); // item is selected TableItem
Code:Record record = store.getRecord((MyModel)item.getModel());
-
3 Jul 2008 4:26 AM #2
You cannot do :
This is incorrect. It could be instead :Code:public ? extends ModelData getModel() { return model; }
and add the <T extends ModelData> parameter on Component class. Darell, what would you think of that ? Not too restrictive ?Code:public T getModel() { return model; }
-
3 Jul 2008 4:40 AM #3
Oops, one should never write code directly in the wiki-editor... I had this construction in mind
which works.Code:public List<? extends ModelData> getModel() { ... }
But components have one model only so i second your suggestion to parametrize the Component class.
-
16 Jul 2008 4:56 AM #4
By the way, I think we (users) should avoid to use the Component.get/setModel methods. If you use a table binder, try binder.getSelection() instead.


Reply With Quote