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

K&B doubt: Inner class name from static context of outer class

 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K&B wrote at the top of page 642:

From outside the outer class instance code (including static method code within the outer class), the inner class name must now include the outer class's name:

MyOuter.MyInner


I've tried and it seems to work fine even without the outer class's name, for instance:


Is this a new feature from Java 6, a characteristic from my compiler or has it always been that way?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

From outside the outer class instance code (including static method code within the outer class), the inner class name must now include the outer class's name:
MyOuter.MyInner




Case #1: Even if the Nested is nested (static inner class), outside the
enclosing class you must refer to it using Outer class name; Nested does not
stand individually.

Case #2 In case of inner class (non nested or non static inner class),
you must have reference to the outer class to create an instance of the
inner class.

Case #3 It is not special, you have created an instance of the outer class
first and in the next line used that reference to create the inner class.


Thus we see that from outside the outer class instance code(including static
method code within the outer class), the inner class name must now include
the outer class's name. K&B

Thanks,
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sasha Ruehmkorf:

From outside the outer class instance code (including static method code within the outer class), ____big_space_here___ the inner class name must now include the outer class's name:

MyOuter.MyInner

means:
outside outer class non-static code && outside outer class static code

the "(including ..." part is related to first part of sentence

However, I read it first time probably as you did. There should be bigger space :-).

[ May 10, 2007: Message edited by: John Stone ]
[ May 10, 2007: Message edited by: John Stone ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic