You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by SYSE | Edvin <es...@syse.no> on 2011/07/09 20:48:21 UTC

Why is TableView#getTableData() typed as List?

I usually add a List of my domainObjects to the TableView on 
initialization, and then later add objects on the fly when more are 
created. Because of the typing on getTableData() however, I can't do:

tableView.getTableData().add(myDomainObject). I have to cast the 
getTableData() to either an untyped List or a List<MyDomainObject> and 
then perform the add. This is because of the following definition of the 
getTableData() method:

public List<?> getTableData() { }

What good does the <?> serve here? Sure, if TableView accepted a generic 
type argument that was used instead of ?, this would be super-handy, but 
now it just seems like an obstacle. I'm no generics expert, so I guess 
it is a good reason for this though? :)

-- Edvin

Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 13.07.2011 16:41, skrev Greg Brown:
>>> Yeah. Parameterizing the method would eliminate that cast. Seems like it might be worth doing.
>>
>> That would be a great help. Should I create a ticket?
>
> Sure.

Done :)

https://issues.apache.org/jira/browse/PIVOT-770

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
>> Yeah. Parameterizing the method would eliminate that cast. Seems like it might be worth doing.
> 
> That would be a great help. Should I create a ticket?

Sure.


Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 12.07.2011 14:07, skrev Greg Brown:
>>>> OK. Out of curiosity, how to you write your code when you want to call listView.getTableData().add(yourObject)?
>>>
>>> You can either cast to a list of the appropriate type or maintain a typed reference to the list data. If the getListData() method was parameterized, your code above would also work.
>>
>> I've been casting it to a list og appropriate type, but it looks so ugly :(
>
> Yeah. Parameterizing the method would eliminate that cast. Seems like it might be worth doing.

That would be a great help. Should I create a ticket?

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
>>> OK. Out of curiosity, how to you write your code when you want to call listView.getTableData().add(yourObject)?
>> 
>> You can either cast to a list of the appropriate type or maintain a typed reference to the list data. If the getListData() method was parameterized, your code above would also work.
> 
> I've been casting it to a list og appropriate type, but it looks so ugly :(

Yeah. Parameterizing the method would eliminate that cast. Seems like it might be worth doing.


Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 11.07.2011 16:05, skrev Greg Brown:
>>> Sure, but I don't want to have to parameterize my ListView. For the most part, ListView doesn't care about the data type. That's up to the model (which is already parameterized).
>>
>> OK. Out of curiosity, how to you write your code when you want to call listView.getTableData().add(yourObject)?
>
> You can either cast to a list of the appropriate type or maintain a typed reference to the list data. If the getListData() method was parameterized, your code above would also work.

I've been casting it to a list og appropriate type, but it looks so ugly :(

-- Edvin

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
>> Sure, but I don't want to have to parameterize my ListView. For the most part, ListView doesn't care about the data type. That's up to the model (which is already parameterized).
> 
> OK. Out of curiosity, how to you write your code when you want to call listView.getTableData().add(yourObject)?

You can either cast to a list of the appropriate type or maintain a typed reference to the list data. If the getListData() method was parameterized, your code above would also work.

G


Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 11.07.2011 15:08, skrev Greg Brown:
>>>> If you parameterize the class, I don't think that causes any problems when you declare an instance without a type argument, does it?
>>> Yes, you get a raw type warning.
>> OK, but then you could declare it with<Object>   or<YourType>  and the warning would go away. The warning would be absolutely justified, and your data is of a certain type, so this seems like the perfect place to use a generic type argument, doesn't it? :)
>
> Sure, but I don't want to have to parameterize my ListView. For the most part, ListView doesn't care about the data type. That's up to the model (which is already parameterized).

OK. Out of curiosity, how to you write your code when you want to call 
listView.getTableData().add(yourObject)?

-- Edvin

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
>>> If you parameterize the class, I don't think that causes any problems when you declare an instance without a type argument, does it?
>> Yes, you get a raw type warning.
> OK, but then you could declare it with <Object>  or <YourType> and the warning would go away. The warning would be absolutely justified, and your data is of a certain type, so this seems like the perfect place to use a generic type argument, doesn't it? :)

Sure, but I don't want to have to parameterize my ListView. For the most part, ListView doesn't care about the data type. That's up to the model (which is already parameterized).

G


Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 11.07.2011 14:55, skrev Greg Brown:
>> If you parameterize the class, I don't think that causes any problems when you declare an instance without a type argument, does it?
> Yes, you get a raw type warning.
OK, but then you could declare it with <Object>  or <YourType> and the 
warning would go away. The warning would be absolutely justified, and 
your data is of a certain type, so this seems like the perfect place to 
use a generic type argument, doesn't it? :)

-- Edvin

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
> If you parameterize the class, I don't think that causes any problems when you declare an instance without a type argument, does it?

Yes, you get a raw type warning.


Re: Why is TableView#getTableData() typed as List?

Posted by SYSE | Edvin <es...@syse.no>.
Den 11.07.2011 14:44, skrev Greg Brown:
>
>> Sure, if TableView accepted a generic type argument that was used instead of ?, this would be super-handy
> True, but that would make declaring the list more of a pain.
>
> My suggestion at the time was to parameterize the property vs. the class, since that would solve the cast problem without requiring a type parameter on the ListView instance. What do you think?
If you parameterize the class, I don't think that causes any problems 
when you declare an instance without a type argument, does it? If that's 
correct, it seems to me that a type parameter on the class is by far the 
best solution.

-- Edvin

Re: Why is TableView#getTableData() typed as List?

Posted by Greg Brown <gk...@verizon.net>.
> public List<?> getTableData() { }
> 
> What good does the <?> serve here?

It avoids the raw type warning we'd get if we simply returned List (vs. List<?>). 

> Sure, if TableView accepted a generic type argument that was used instead of ?, this would be super-handy

True, but that would make declaring the list more of a pain.

A similar issue came up a while back - the thread is here:

http://apache-pivot-users.399431.n3.nabble.com/why-ListButton-getListData-returns-List-lt-gt-td2311099.html

My suggestion at the time was to parameterize the property vs. the class, since that would solve the cast problem without requiring a type parameter on the ListView instance. What do you think?

G