Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>MyActivity.this</code> would reference the instance of the "outer" MyActivity class when your code ran in an inner class. -- Does it? If so, why would you need the <code>host</code> variable?</p> <p><em>Update:</em> It only just occured to me that you may be missing the fact that everything you would access via <code>MyActivity.this</code> from within an <em>inner</em> class, you can access via <code>host</code> in your specific setup.</p> <p><em>Update:</em> You seem to have a wrong understanding of the meaning of <code>this</code>. Originally, it stands for <em>this object</em>, i.e. the class in which your code runs.</p> <p>With the additional notation <code>Class.this</code>, Java enables you to access the instance of the outer class of your code, but only from an inner class.</p> <p>In the following example, <code>Class.this</code> works:</p> <pre><code>class A { int a; class B { void process_a_in_A() { A.this.a++; } } // however, this does NOT work b/c // static inner classes do not have references t oouter classes static class C { void process_a_in_A() { // error -- class A.C is detached from its outer class A A.this.a++; } } } </code></pre> <p>Also, in the following example, <code>Class.this</code> does not work. The reason is simply that the system cannot know whether there is an Instance of class A and which one of the possibly many instances of class A you want to refer to.</p> <pre><code>class A { int a; } class B { void process_a_in_A() { // A here is a class name, not an object reference; // so A.this is meaningless in this context A.this.a++; } } </code></pre> <p>Once again, please be aware that you asked a question without providing the necessary information to answer it <em>specifically</em>, so it can only be answered in general and it looks like you have a wrong understanding about inner classes and the <code>Class.this</code> notation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload