It is unclear to me. Maybe if we comb through specs we'll find evidence that inner classes should be treated the same as normal classes. However in spirit, an inner class depends on the outer instance, the class doesn't exist beyond the instance. This is different from "normal" classes whose existence is basically perpetual. Two inner classes of two outer instances of course are somewhat related each other, being created by the same source code, yet that doesn't mean they must be identical or even equal.
There are evidence that Java designers intended this way, that an inner class in spirit lives within the scope of the outer instance. For example, the curious syntax outerInstance.new InnerClass()
. For example, no static variables, no static initializers for inner classes. In the discussion of class unloading [1], we see that the argument doesn't really apply to inner classes, it's conceivable that inner classes can be unloaded! It is conceivable that a VM creates a new inner class for each new outer instance.
Practically that's not the case, inner classes are indeed treated the same as normal classes. But conceptually, I'll always think of them differently, as instance-private classes.
[1] http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.7
Update: according to [2]
Two reference types are the same run-time type if They ... have the same binary name
and [3]
The binary name of an anonymous class (§15.9.5) consists of the binary name of its immediately enclosing type, followed by $, followed by a non-empty sequence of digits.
So one anonymous class has one binary name, therefore only one run-time type. The spec guarantees us that different instances of an anonymous class have identitcal class.
[2] http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.4
[3] http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909