Hi,

the symbol is in the scope of the addStock() method. Each invocation
of that method gets a new instance of symbol. It's declared final, so
it can't change.

Note also, that the symbol instance is retained by the JVM because it
can be accessed by the ClickHandler. The ClickHandler in turn is
referenced by the removeStockButton. As soon as you dereference the
removeStockButton (i.e. you remove all references to it), the symbol
instance can be garbage collected (assuming there are no other
references to it).

HTH
Chris


On Jan 19, 4:20 pm, Russ <[email protected]> wrote:
> If the symbol variable gets re-assigned each time the user adds a
> stock, I would assume that the symbol variable contains the value of
> the most recently added stock. But it doesn't because the removeButton
> knows which stock to remove - regardless of what was added last. the
> variables symbol and removedIndex are different for each instance of
> the removeButton. Why is this?
>
> //the symbol variable is assigned here:
> final String symbol = newSymbolTextBox.getText().toUpperCase().trim();
>
> //yet symbol and removedIndex contain a different value for each
> removeButton indicated below. Why?
>
> removeStockButton.addClickHandler(new ClickHandler() {
> public void onClick(ClickEvent event) {
> int removedIndex = stocks.indexOf(symbol);//why doesn't symbol contain
> the last stock added?
> stocks.remove(removedIndex);
> stocksFlexTable.removeRow(removedIndex + 1);
>       }
>  });
-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reply via email to