-1

In the first paragraph of Josh Bloch's book Effective Java's 29th Item it is said that

it is the container that is parameterized

Doesn't the author discard Sets and Maps as parameterized types by above declaration?

dimo414
  • 47,227
  • 18
  • 148
  • 244
user961690
  • 698
  • 1
  • 11
  • 22

1 Answers1

0

The purpose of Item 29 (as I just discussed in another answer) is to demonstrate other usages of generics and paramterized types in addition to collections. The whole preceding chapter has essentially been discussing parameterized collection types, so Bloch is clearly not discarding Map and Set and other parameterized types - he is distinguishing them from a different type of pattern, which he calls a "heterogeneous container".

Compare an interface like:

interface Collection<E> {
  void put(E element);
  E get(int index);
}

with something like:

interface HeterogeneousContainer {
  <T> void put(Class<T> type, T instance);
  <T> T get(Class<T> type);
}

Notice that Collection itself has a type parameter, while HeterogeneousContainer does not. This is the distinction Bloch is trying to draw in this item - that you can use type parameters in more powerful ways than simply creating type-safe collections.

dimo414
  • 47,227
  • 18
  • 148
  • 244