public class MainMenuScreen extends GameScreen { ... btn.setClickListener(new ClickListener() { @Override public void click(Button btn) { game.removeScreen(/*Вот здесь нужно получить доступ к объекту класса MainMenuScreen*/); } }); ... } 

Above in the comments it says what I need. Is there such a possibility?

So far, the work has taken a separate method

 public class MainMenuScreen extends GameScreen { ... btn.setClickListener(new ClickListener() { @Override public void click(Button btn) { startGameLoop(); } }); ... private void startGameLoop(){ // нужная работа с обращением к this } } 

but the possibility of direct access in the first version is of interest.

Hopefully available explained :)

    3 answers 3

    MainMenuScreen.this. - like this.

    • Yes, so even smarter. - Nofate
    • one
      Thank you for what you need. - AlexDenisov

    add method to MainMenuScreen

     private MainMenuScreen getInstance() { return this; } 

    and pull on health in the inner classrooms.

    • one
      I ranked such solutions (as well as my own) as crutches :) I was looking for the solution proposed by kENNAAAAA - AlexDenisov
    • I do not argue. It is just that the last few days have to forward instances between different levels of different hierarchies, the mind is already beyond reason. - Nofate

    In order to have access to a field from an anonymous inner class, you need to mark it as final .

    • here we are not talking about the field of the framing class, but about the instance itself. - Nofate
    • Yes you are right. Wrong question understood. - test81278