JDK-5011312 : wildcard capture (snapshotting)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-03-10
  • Updated: 2017-05-16
  • Resolved: 2004-04-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b49Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
The JLS third edition being written is taking an approach to wildcard capture
that makes its use pervasive in rvalue contexts even when no generic method is
being called.  This solves a number of thorny problems both in the specification
and in existing APIs that want to take advantage of generics.  See, for example,
4916563, 4976895, 4916650.
See also <http://forum.java.sun.com/thread.jsp?forum=316&thread=499114>.
See also <http://forum.java.sun.com/thread.jsp?forum=316&thread=512445>.

However, javac implements a much simpler scheme
based on substitution and rewriting member types.  javac must be changed to
obey the specification and support the general wildcard capture mechanism,
also known informally as snapshotting.

In addition to those three bugs, there is one case of a signature in
java.util.Collections that is more complex than necessary to work around
this problem.  We have

public static <T> void copy(List<? super T> dest, List<? extends T> src);

With the addition of support for snapshotting, this can be rewritten

public static <T> void copy(List<T> dest, List<? extends T> src);

A method with the former signature should be able to call one with the latter
signature - the call is typesafe - and snapshotting should allow the compiler
to support this.

If this can be implemented in time for Tiger, the signature for
Collections.copy should be simplified.

The following program should compile with no errors:

import java.util.*;

class C {
    public static <T> void copy1(List<? super T> dest, List<? extends T> src) {
        copy1(dest, src);
        copy2(dest, src); // oops
        copy3(dest, src); // oops
    }
    public static <T> void copy2(List<T> dest, List<? extends T> src) {
        copy1(dest, src);
        copy2(dest, src);
        copy3(dest, src); // oops
    }
    public static <T> void copy3(List<? super T> dest, List<T> src) {
        copy1(dest, src);
        copy2(dest, src); // oops
        copy3(dest, src);
    }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b49 tiger-beta2
08-07-2004

PUBLIC COMMENTS ...
08-07-2004

EVALUATION In progress. ###@###.### 2004-03-10
10-03-2004