1. #1
    Ext User
    Join Date
    May 2008
    Posts
    105
    Vote Rating
    0
    Grandiosa is on a distinguished road

      0  

    Default Component.getModel() should use wildcard return value

    Component.getModel() should use wildcard return value


    Shouldn't this method on Component

    Code:
    public ModelData getModel() {
        return model;
    }
    instead be

    Code:
    public ? extends 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:
      Record record = store.getRecord(item.getModel());  // item is selected TableItem
    But this fails since the the getRecord expects a MyModel instance, so a cast is needed:

    Code:
      Record record = store.getRecord((MyModel)item.getModel());

  2. #2
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    You cannot do :
    Code:
    public ? extends ModelData getModel() {
        return model;
    }
    This is incorrect. It could be instead :
    Code:
    public T getModel() {
        return model;
    }
    and add the <T extends ModelData> parameter on Component class. Darell, what would you think of that ? Not too restrictive ?

  3. #3
    Ext User
    Join Date
    May 2008
    Posts
    105
    Vote Rating
    0
    Grandiosa is on a distinguished road

      0  

    Default


    Oops, one should never write code directly in the wiki-editor... I had this construction in mind

    Code:
        public List<? extends ModelData> getModel() {
            ...
        }
    which works.
    But components have one model only so i second your suggestion to parametrize the Component class.

  4. #4
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    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.

Thread Participants: 1