Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static inner classes

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I was going through the concept of static inner classes and how their objects are created ...Guys please advise me or tell me a scenario where the static nested classes would be helpful ..and what performance impact would they bring out ...?
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I like static inner classes as types that are only useful for helper objects inside the enclosing class, or when they're logically an internal part of the enclosing class and not significant enough to have a separate source file.

As an example, you could have the class ChessPiece.Color, which models the color of a chess piece; usually black or white. Here Color is logically an internal part of the ChessPiece.

There should be no performance penalty or benefit. To the JVM, they're the same as every other class. They're just another way for you to structure your code. I know many people don't like them and never use them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic