WORK AROUND
tim.bell@Eng 2000-06-29
The source code (LinkedHashMap.java) mentioned
in the Evaluation is available as part of the
J2SDK 1.3 beta SCSL source bundle, which can
be obtained from:
http://www.sun.com/software/java2/download.html
After you agree to the SCSL license and download
the source bundle, look for:
ext/jpda/src/share/classes/com/sun/tools/jdi/LinkedHashMap.java
|
EVALUATION
This should probably be an FAQ. It is intentional that a class cannot
implement List and Map simultaneously. Even if it were possible from a method
signature point-of-view, it would be impossible semantically. In particular,
the equals contracts implies that it's not possible for a Map to be equal
to a List, or vice versa. Similarly, the hashCode contracts would mandate two
different HashCode computations.
It is possible to get a very similar effect by having an object that
implements Map and provides a List-view operation ("asList()"), or vice-versa.
Also, it's possible to implement a Map that guarantees insertion-order
iteration but does not implement the List interface. I've attached source
code for such a class to this bug report. Customers can use this code freely
(as-is).
joshua.bloch@Eng 1998-11-06
|