aspose file tools
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 Groovy Fundamentals video training course this week in the Groovy 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: 42677
It should all be in the Java Language Specification, but the Java Tutorials are easier to understand.
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2270

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: 8657

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).


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 3792

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.
I agree. Here's the link:
subject: Discussion on Static Nested Classes