Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing an object without a reference

 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was going through the following piece of code



Is there any other way of accessing the Test object inside the inner class apart from the one mentioned in line #1, if i am creating the Test object from somewhere else and i haven't got a reference to it ?

Thanks,
Adithya.
 
Rituraj tyagi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I'm also pursuing OCJP and gone through above problem and just extended adithya's example to clear my understanding as follows:-


And got this output :-

Test method invoked in main with innerTest as local from the inner private class
both instance equal

Now what I understand from above this that the line Test test = Test.this got the refrence of the class containing it . Please correct me if I'm wrong.
Thanks

 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good work
 
Rituraj tyagi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All I was going through the K & B again and found in 8 th chapter that this syntax is used to refer by inner class to reference the current instance of the outer class. refer page 669.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic