The question is not of practical importance, but very interesting in terms of understanding the language.

public class A { private class B {} private String myFinalNameField; private B b = new B() { private void myMethod(String myFinalNameFields) { [???]myFinalNameFields = myFinalNameFields; } }; } 

How to assign a class A value to the myFinalNameFields field of the myFinalNameField parameter of the myFinalNameFields method of the B class? Most likely, I incorrectly formulated the question, this can be done by adding for example a prefix:

 public class A { private class B {} private String prefixMyFinalNameField; private B b = new B() { private void myMethod(String myFinalNameFields) { prefixMyFinalNameField = myFinalNameFields; } }; 

Is it possible to access the private non-static field of an external class, something like this or super . Those. to have absolutely identical field names, but to distinguish which variable belongs to which class, it is more accurate to carry out the assignment.

  • 2
    Вопрос не несет практической значимости - not true, a very useful question - diraria

1 answer 1

If I correctly understood the essence of the question, then you can refer to this variable as follows:

 A.this.myFinalNameFields = myFinalNameFields; 

I will explain a little:

 class A { private class B {} private String myFinalNameFields; private B b = new B() { private String myFinalNameFields; private void myMethod(String myFinalNameFields) { A.this.myFinalNameFields = myFinalNameFields; //Присвоит значение полю класса A this.myFinalNameFields = myFinalNameFields; //Присвоит значение полю класса B } }; } 
  • Thank you so much! Maybe I incorrectly posed the question when I searched in Google, i.e. I did not find the answer. But he knew that using the prefix is ​​not the only option. Exactly what is needed! - Eugene