itemId and item

I found there is little difference between them after reading some demos.

In the Container,
Item addItem(Object itemId),
I can use item as its parameter
In the ItemClickEvent event,
public Object getItemId()
,actually,an item is returned,not the id
I was coufused by the id,I need your advice.


Actually no - you can use any object as itemId, but not actually the Item itself, since you don’t have it before you make this call. (Actually a Container could allow this, but most don’t; some are set us so that itemId == item, though)

This is not true; it always returns the itemId. However, in the special case when itemId == item, that will appear true…

Summary: itemId and Item are two different things, itemId is the unique id that identifies an Item instance within a Container - however, some Containers are set up so that the item instance is used as itemId, which can be convenient (but confusing).

Best Regards,