Inner anonymous classes have full access to the private members of the enclosing class. I haven't gotten to this point in the tutorial yet, but the only way I believe that this compiles is that "symbol" is a member of the outer class (probably StockWatcher.java, yes?). So this code can see any value in that field.
On Apr 27, 4:36 pm, Rob Tanner <[email protected]> wrote: > In working through the StockWatcher tutorial and I'm on "Add a button > to remove stocks from the stock list" under Step #5. While the > function works perfectly there is, for me, a logical disconnect. In > my mind, the code shouldn't work (perhaps it's my lack of > understanding of anonymous sub-classes): > > // Add a button to remove this stock from the table > Button removeStockButton = new Button("X"); > removeStockButton.addClickHandler(new ClickHandler() { > public void onClick(ClickEvent event) { > int removedIndex = stocks.indexOf(symbol); > stocks.remove(removedIndex); > stocksFlexTable.removeRow(removedIndex + 1); > } > }); > stocksFlexTable.setWidget(row, 3, removeStockButton); > > The "onClick" handler is executed when the removeStockButton is > clicked. The value of "symbol" comes from the newSymbolTextBox when > the stock is entered. So how does the onClick handler know the value > of "symbol" when the button is pressed? > > Thanks, > Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
