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

Use of static inner classes

Paul Barnes

Joined: Oct 11, 2001
Posts: 4
I am trying to figure out the purpose of using a static inner class...
1. Why wouldn't you just create a package level static class instead of a static inner class which ends up being equivalent to a package level static class anyway?
2. What are the pros of cons of using them?
3. And can anyone give me an instance of some code where a static inner class was used a data store for general use by the system?
Thanks for helping me to understand this...
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
It's one way of controlling namespace.

"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Even if you declare the class as static other classes can see it. The inner class lets you hide from everyone.

Please ignore post, I have no idea what I am talking about.
Shanee Bradley

Joined: Oct 12, 2001
Posts: 2
There are useful to hide a node class in a Linked list or hide an iterator...all kinds of uses.
I agree. Here's the link:
subject: Use of static inner classes
It's not a secret anymore!