Instantiating inner class

I think you want to declare the HashPerson class as static. Otherwise it can only be instantiated in the context of the containing class, either in a method of the containing class or using code like this:

ContainingClass container = new ContainingClass();
HashPerson william = container.new HashPerson("willy");

Actually, my rule-of-thumb is to make any nested class static, unless I have a special reason not to. This is also more efficient, because non-static nested classes (called inner classes) always contain an implicit reference to the containing object.

Leave a Comment