• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Discussion on Static Nested Classes

 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Larsen.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should all be in the Java Language Specification, but the Java Tutorials are easier to understand.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I myself avoid inner classes and static stuff as much as possible.
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

Winston
 
Stephan van Hulst
Bartender
Posts: 6311
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic