File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes static inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "static inner classes" Watch "static inner classes" New topic

static inner classes

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 203

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

Joined: Sep 20, 2010
Posts: 4627

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.

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: static inner classes
It's not a secret anymore!