Originally, we used List<Object>, but this caused compilation issues with 
setListData(). Perhaps getListData() should return List<Object> while 
setListData() takes List<?>?
G

On Jan 22, 2011, at 6:16 PM, calathus wrote:

> hi,
> I found my BXML  to Java translator had an issue  due to some "strange" usage 
> of anonymous type in wtk.
> 
> in pivot wtk classes, there are a few classes using anonymous type('?'), for 
> example, in ListButton, getListData defined to return List<?>.
> List<?> getListData()
> 
> This make following code compile error.
> getListData().add(new ListItem())
> 
> In order to pass compiler, we need to use cast.
> 
> ((List<Object>)getListData()).add(new ListItem())
> or
> ((List<ListItem>)getListData()).add(new ListItem())
> ...
> since add method is  frequently used, this cast is quite verbose.
> if we declare variable, we may need to use only one cast, but often these 
> codes are generated by a program, it is much simpler to use above approach.
> 
> The only advantage of using anonymous type is that it allows to cast to 
> another parametrized list type(e.g, List<ListItem>)) while if we use 
> List<Object> as return type this is not possible, but how often such a cast 
> is used??
> 
> there are similar cases in wtk classes:
> 
>  grep -R "<?>" * | grep -v .svn | grep private | grep wtk | grep "List<"
> wtk/src/org/apache/pivot/wtk/TreeView.java:        private List<?> branchData;
> wtk/src/org/apache/pivot/wtk/TreeView.java:    private List<?> treeData = 
> null;
> wtk/src/org/apache/pivot/wtk/TableView.java:    private List<?> tableData = 
> null;
> wtk/src/org/apache/pivot/wtk/ListView.java:    private List<?> listData = 
> null;
> wtk/src/org/apache/pivot/wtk/SuggestionPopup.java:    private List<?> 
> suggestionData;
> wtk/src/org/apache/pivot/wtk/ListButton.java:    private List<?> listData;
> wtk/src/org/apache/pivot/wtk/Spinner.java:    private List<?> spinnerData = 
> null;
> 
> Have you considered this kind of issue?
> 
> -- 
> Cheers,
> calathus
> 
> 
> 

Reply via email to