Wednesday, November 03, 2010

Use of static inner classes

We have HashMap.Entry class that is declared as a static inner class, I was searching for why it has been declared as static inner class and I found this post, which talks about when to use what type of inner classes.

In Short,

  1. Convenient way of grouping classes without using packages
  2. To create an instance of this class, we don't need outer class's object
  3. It will help you to extend from some other class

java.util.HashMap.Entry is used in
  • java.util.LinkedHashMap.Entry
  • java.util.HashMap.EntrySet
  • java.util.HashMap.HashIterator
  • java.util.LinkedHashMap