pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calathus <calat...@gmail.com>
Subject why ListButton.getListData returns List<?> ?
Date Sat, 22 Jan 2011 23:16:35 GMT
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

Mime
View raw message