java - Can I access an outer class's field from a static inner class? -


i have class has static inner class:

class {     private list<string> list;      public static class b {         // want update list here without making list static          // don't have object outer class     } } 

as can see other answers need non-static inner class that.

if cannot make inner class non-static can add required getter , setter method in outer class , access them creating instance of outer class inside inner static class:

public class {     private list<string> list = new arraylist<string>();     public list<string> getlist() {         return list;     }     public void setlist(list<string> list) {         this.list = list;     }     public static class b {         // want update list here without making list static         void updlist() {             a = new a();             a.setlist(someotherlist);             system.out.println(a.getlist());         }     } }  

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -