0

I saw the following code:

 mActionMode = OverviewActivity.this
        .startActionMode(mActionModeCallback);

I saw this here in the Android Dev. tutorial

What is the benefit of calling function like this ? I have changed the code to:

mActionMode = startActionMode(mActionModeCallback);

but, I didn't see any change.

kaushik
  • 2,308
  • 6
  • 35
  • 50

2 Answers2

2

The difference (if there is any) is that it calls the outer classes method.

class Outer {
   void methodA() { }

   class Inner {
       void methodA() { }

       void method() {
            methodA(); // call my methodA();
            Outer.this.methodA(); // calls the Outer.methodA();
       }
   }
}

It is possible the developer liked to be specific even if he/sge didn't need to be.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

It's useful when you have an outer class with a member with the same name as a nested class member:

public class Test {

    public static void main(String[] args) {
        new Test().new Inner().run();
    }

    class Inner {
        public void run() {
            foo(); // Prints Inner.foo
            Test.this.foo(); // Prints Test.foo
        }

        public void foo() {
            System.out.println("Inner.foo");
        }
    }

    public void foo() {
        System.out.println("Test.foo");
    }
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194