--- old/src/java.base/share/classes/java/util/doc-files/coll-designfaq.html 2017-08-18 15:03:15.274993692 -0700 +++ new/src/java.base/share/classes/java/util/doc-files/coll-designfaq.html 2017-08-18 15:03:15.062984419 -0700 @@ -1,7 +1,4 @@ - - - + - - + Java Collections API Design FAQ +

Java Collections API Design FAQ

-
+
This document answers frequently asked questions concerning the design of the Java collections framework. It is derived from the large volume of traffic on the collections-comments alias. It @@ -105,10 +101,10 @@ collections that send out Events when they're modified? -
+

Core Interfaces - General Questions

    -
  1. Why don't you support immutability +
  2. Why don't you support immutability directly in the core collection interfaces so that you can do away with optional operations (and UnsupportedOperationException)? @@ -168,7 +164,7 @@ very small set of core interfaces that can throw a runtime exception.

  3. -
  4. Won't programmers have to surround any +
  5. Won't programmers have to surround any code that calls optional operations with a try-catch clause in case they throw an UnsupportedOperationException?

    It was never our intention that programs should catch these @@ -176,7 +172,7 @@ should only arise as a result of programming errors, in which case, your program will halt due to the uncaught exception.

  6. -
  7. Why isn't there a core interface for +
  8. Why isn't there a core interface for "bags" (AKA multisets)?

    The Collection interface provides this functionality. We are not providing any public implementations of this interface, as we think @@ -185,7 +181,7 @@ atop AbstractCollection (for example, the Collection returned by Map.values).

  9. -
  10. Why didn't you use "Beans-style +
  11. Why didn't you use "Beans-style names" for consistency?

    While the names of the new collections methods do not adhere to the "Beans naming conventions", we believe that they are @@ -207,10 +203,10 @@ case. Thus, we adopted the "traditional" JDK style rather than the Beans style.

-
+

Collection Interface

    -
  1. Why doesn't Collection extend Cloneable +
  2. Why doesn't Collection extend Cloneable and Serializable?

    Many Collection implementations (including all of the ones provided by the JDK) will have a public clone method, but it would @@ -224,7 +220,7 @@ this type, and use the addAll method to copy the elements of the original collection into the new one.

  3. -
  4. Why don't you provide an "apply" method +
  5. Why don't you provide an "apply" method in Collection to apply a given method ("upcall") to all the elements of the Collection?

    This is what is referred to as an "Internal Iterator" in the @@ -235,7 +231,7 @@ this functionality is increased by the fact that it requires a public interface to describe upcalls.

  6. -
  7. Why didn't you provide a "Predicate" +
  8. Why didn't you provide a "Predicate" interface, and related methods (e.g., a method to find the first element in the Collection satisfying the predicate)?

    It's easy to implement this functionality atop Iterators, and @@ -244,14 +240,14 @@ weight. It could be added to the Collections class at a later date (implemented atop Iterator), if it's deemed useful.

  9. -
  10. Why don't you provide a form of the +
  11. Why don't you provide a form of the addAll method that takes an Enumeration (or an Iterator)?

    Because we don't believe in using Enumerations (or Iterators) as "poor man's collections." This was occasionally done in prior releases, but now that we have the Collection interface, it is the preferred way to pass around abstract collections of objects.

  12. -
  13. Why don't the concrete implementations +
  14. Why don't the concrete implementations in the JDK have Enumeration (or Iterator) constructors?

    Again, this is an instance of an Enumeration serving as a "poor man's collection" and we're trying to discourage that. Note @@ -259,7 +255,7 @@ should have constructors that take a Collection (and create a new Collection with the same elements).

  15. -
  16. Why don't you provide an Iterator.add +
  17. Why don't you provide an Iterator.add method?

    The semantics are unclear, given that the contract for Iterator makes no guarantees about the order of iteration. Note, however, @@ -267,10 +263,10 @@ guarantee the order of the iteration.

-
+

List Interface

    -
  1. Why don't you rename the List +
  2. Why don't you rename the List interface to Sequence; doesn't "list" generally suggest "linked list"? Also, doesn't it conflict with java.awt.List?

    People were evenly divided as to whether List suggests linked @@ -285,16 +281,16 @@ import java.awt.*; import java.util.List; // Dictates interpretation of "List"

  3. -
  4. Why don't you rename List's set +
  5. Why don't you rename List's set method to replace, to avoid confusion with Set.

    It was decided that the "set/get" naming convention was strongly enough enshrined in the language that we'd stick with it.

-
+

Map Interface

    -
  1. Why doesn't Map extend +
  2. Why doesn't Map extend Collection?

    This was by design. We feel that mappings are not collections and collections are not mappings. Thus, it makes little sense for @@ -317,10 +313,10 @@ Lists.

-
+

Iterator Interface

    -
  1. Why doesn't Iterator extend +
  2. Why doesn't Iterator extend Enumeration?

    We view the method names for Enumeration as unfortunate. They're very long, and very frequently used. Given that we were adding a @@ -329,7 +325,7 @@ names. Of course we could support the new and old names in Iterator, but it doesn't seem worthwhile.

  3. -
  4. Why don't you provide an +
  5. Why don't you provide an Iterator.peek method that allows you to look at the next element in an iteration without advancing the iterator?

    It can be implemented atop the current Iterators (a similar @@ -338,10 +334,10 @@ that everyone has to implement.

-
+

Miscellaneous

    -
  1. Why did you write a new collections +
  2. Why did you write a new collections framework instead of adopting JGL (a preexisting collections package from ObjectSpace, Inc.) into the JDK?

    If you examine the goals for our Collections framework (in the @@ -363,7 +359,7 @@ as we can to keep them small and manageable, so that Java continues to be an easy, fun language to learn and to use.

  3. -
  4. Why don't you eliminate all of the +
  5. Why don't you eliminate all of the methods and classes that return "views" (Collections backed by other collection-like objects). This would greatly reduce aliasing. @@ -380,7 +376,7 @@ taking List on input do not have to write secondary forms taking an offset and a length (as they do for arrays).

  6. -
  7. Why don't you provide for +
  8. Why don't you provide for "observable" collections that send out Events when they're modified?

    Primarily, resource constraints. If we're going to commit to @@ -390,9 +386,9 @@ facility on top of the public APIs.

-
+

-Copyright © 1998, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
+Copyright © 1998, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.