BeanItemContainer in Vaadin 6.5.2

Hi guys,

I noticed the BeanItemContainer constructor is changed in Vaadin 6.5.2. The one I used to use is deprecated:

List<Customer> pa = blabla....;
BeanItemContainer<Customer> param = null;
param = new [s]
BeanItemContainer
[/s]<Customer>(pa);

Instead it is changed to:

BeanItemContainer<Customer> param = null;
param = new BeanItemContainer<Customer>(Customer.class, pa);

Can someone explain what is the reason of this change. It is a bit redundant to have the class defined twice, right?

Br,
Xuan

The type definition () is only available at compile time and the Class is needed at run time to determine what properties there are in the class. Earlier it just had a look at the first item in the collection and used it, which does not work if the collection is empty or if the first object happens to be something else than a Customer (e.g. a class that extends Customer).

This is a common annoyance with Java up to release 6. If a class is defined with a Generic, , you cannot write T.class to know what class was actually used to instantiate the generic. This is one of the planned enhancements to Java.

There is no safe way to get this information, even with introspection. You are left with looking at (say) the first item of a collection and extrapolating, or (which is what most people do) explicitly pass the class to instantiate. Yuk.