Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8061426

Wildcard should have multiple bounds similar to type variables

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Other
    • Icon: P5 P5
    • None
    • None
    • specification
    • None

      Currently wildcards can only have one bound, whereas type variables can have
      multiple bounds:

      <T extends Number & Cloneable> void m(List<T> l);

      A similar method could be expressed using wildcards with multiple bounds:

      void m(List<? extends Number & Cloneable> l);

      Among the benefits of using wildcards over type variables are:

      1. The signature becomes simpler since you do not need to add a type variable
         to express the constraints on l.
      2. The signature using wildcards states implicitly that you do not intent to
         modify l (at least not add new non-null elements).
      3. It is not necessary to understand the rules of inference to read the
         signature.

      ###@###.### 2004-05-25

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: