Re: A nested class and the fields of her enclosing class
Mark Space ha scritto:
Giampiero Mughini wrote:
Hi everyone.
As far as I know, nested classes have access to all the private class
fields and methods of the enclosing class. When I try to access from a
nested class to an instance of the Interface Map (or an implementing class
such as HashMap, Hashtable, ...) in the enclosing class, this appears
empty. Is this behaviour normal? How can I see what really is in the map?
Yes, if the program compiled, you are probably accessing the map
correctly. You might be accessing a variable that hides or shadows the
map variable. We'd need an example to be sure.
Here is my code.
public class Upload {
private Hashtable<String, Long> filesTable;
private JButton button;
protected void startUpload(Hashtable<String, Long> myFilesTable) {
this.filesTable = myFilesTable;
if (!filesTable.isEmpty()) System.out.println("is not Empty");
startNewWindow(); //opens the GUI
button.addActionListener(new MyActionListener());
}
// start nested class
public class MyActionListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
if (filesTable.isEmpty())
System.out.println("is Empty");
}
}; //end nested class
}
And I see every time on my console first "is not Empty" then "is Empty"
after clicking on the button of my GUI :-/
--
questo articolo e` stato inviato via web dal servizio gratuito
http://www.newsland.it/news segnala gli abusi ad abuse@newsland.it