vico
vico

Reputation: 18251

synchronise on outer class object

Hello, I have runnable inner class. Outer class waits inner class notification. After notification is done I need outer class to read some inner class object state params. For this reason I make sleep inner class and wait for outer class read parameters and send notification. For this reason I need synchronise on outer class object.

How to get outer class object from inner class?

Upvotes: 1

Views: 94

Answers (1)

nanofarad
nanofarad

Reputation: 41281

If outer class is called Outer and inner class is Outer.Inner, then you can get your outer instance with:

Outer.this

when in the inner scope.

You can call methods and access fields this way, but you cannot assign to Outer.this.

Upvotes: 3

Related Questions