Locking and synchronization between outer and inner class methods?

后端 未结 3 1084
滥情空心
滥情空心 2020-12-04 01:33

My question is if I have some code like the following -:

public class OuterClass{
   public class InnerClass{
          public synchronized methodA(){ /* doe         


        
3条回答
  •  萌比男神i
    2020-12-04 02:14

    It will use the this of the immediately enclosing class so the inner class. You can use instead:

    public void m() {
        synchronized(OuterClass.this) {
        }
     }
    

提交回复
热议问题