Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic