-4

I have a simple class:

Public class Store {
   Product product = new Product();

   public class Product{
      Store getStore(){
         //What does this return statement mean?
         return Store.this;
      }
   }
}

I am wondering whether the Store.this; in the return statement means the instance of Store which hosts the product?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Mellon
  • 37,586
  • 78
  • 186
  • 264
  • 5
    `"I am wondering whether the Store.this; in the return statement means the instance of Store which hosts the product?"`: Yes it does. That's what `Store.this` means. – Hovercraft Full Of Eels Jun 23 '13 at 16:05
  • 1
    Com'on, can't you figure out with some debug? –  Jun 23 '13 at 16:06
  • 1
    RC. come on, teach me ;) – Mellon Jun 23 '13 at 16:07
  • you are returning the outsider object.. – nachokk Jun 23 '13 at 16:09
  • 8
    This question shows a clear lack of research before posting. StackOverflow is not a replacement for your compiler, IDE, or Google. – Marko Topolnik Jun 23 '13 at 16:10
  • Marko, I see. Please calm down, don't criticize me like this, if I know how to prove my guessing I won't post it. But I will try to think carefully before posting next time. Thank you everyone. – Mellon Jun 23 '13 at 16:20
  • @Mellon I have stated what I take as the opinion of the StackOverflow community on your question. There are no emotions, negative or otherwise, involved. – Marko Topolnik Jun 23 '13 at 16:43

3 Answers3

3

Yes it is. See JLS 15.8.4: Qualified this:

Any lexically enclosing instance (§8.1.3) can be referred to by explicitly qualifying the keyword this.

Let C be the class denoted by ClassName. Let n be an integer such that C is the n'th lexically enclosing class of the class in which the qualified this expression appears.

The value of an expression of the form ClassName.this is the n'th lexically enclosing instance of this.

In this case, the lexical enclosing instance is the Store instance.

zw324
  • 26,764
  • 16
  • 85
  • 118
0

You will need an instance of the outer class (in this case, Store) to create an instance of the inner class (in this case, Product). So, in the inner class you can use OuterClass.this to mark the difference between the this instance returned by the inner class.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
0
Public class OuterClass{    
   public class InnerClass{
         //OuterClass.this is used to refer the current reference of outer class
         //this referes to the current instance of innner (self) class
   }
}
stinepike
  • 54,068
  • 14
  • 92
  • 112