I have a Server and ServerConnection classes where a user is connected through the Server and then a ServerConnection instance is created for him and the user is maintained there.
In Server I have some data and I would like the ServerConnection instance to be able to access it.
How it’s possible?
The ServerConnection instance is created inside the Server class so it’s not easy to figure out how to go up one level (to Server class) to get data from it.
If
ServerConnectionis an inner class ofServer, you can directly access theServerinstance’s fields (even if it is shadowed):A better approach might be to pass the
Serverinstance to theServerConnectionand expose the data by getters: