Re: Error message I can't figure out
On 02/25/2010 05:42 PM, Roedy Green wrote:
Could Sun fix it just by adding an "implements Serializable" to the
Values nested class?
The value set class (and those for the key and entry sets, FWIW) is
defined as an inner class. Therefore, all of its constructors implicitly
have an argument of TreeMap, which makes making the Serializable a
little more problematic. Sun even gives the following warning:
Note - Serialization of inner classes (i.e., nested classes that are not
static member classes), including local and anonymous classes, is
strongly discouraged for several reasons.
As to why this was done, I cannot say for certain. The sub map return
stuff is serializable on the other hand, which leads me to believe that
the developers of Java decided that the value, key, and entry sets are
merely views into the data of a TreeMap and should not live on their own
while submaps of a TreeMap are full-fledged maps in their own rights and
should be able to be divorced from the original.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth