This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Discussion on Static Nested Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Discussion on Static Nested Classes" Watch "Discussion on Static Nested Classes" New topic

Discussion on Static Nested Classes

Larsen Raja
Ranch Hand

Joined: Nov 28, 2011
Posts: 58

I would like to share my views and your views on Static Nested Classes.

From my analysis, I comclude that static Nested Classes are similar to a spearate non-inner class except it has a few privileges.

For ex:
Static Nested Classes can access static members of enclosing class witout namespace. To say, this behaviour is exaclty like a static method enclosed in a class.

Please share your views.


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
It should all be in the Java Language Specification, but the Java Tutorials are easier to understand.
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

I myself avoid inner classes and static stuff as much as possible.

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8956

Roberto Perillo wrote:I myself avoid inner classes and static stuff as much as possible.

Actually, I find static nested classes (I don't like the term 'inner') very useful, because it defines exactly what I want: a class that only has meaning within the context of another class, and which should probably be qualified with it when used from outside (eg, AbstractMap.SimpleEntry).


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4642

I agree, static nested classes can be great, especially when they're completely for the convenience of their enclosing class (like a tuple, or some other aggregation of data). In this case, you don't have to give them any methods, you can just use them as records and access their private fields directly.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: Discussion on Static Nested Classes
It's not a secret anymore!