<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <tt>Nice catch.  Yes, this would cause heap pollution.  As would the
      following Java 5 code:<br>
      <br>
          private Collection<?> collection = new ArrayList<?>();<br>
          public <T> Collection<T> c() { return
      (Collection<T>) collection; }<br>
      <br>
      The trouble is, the unchecked warning is in the library
      implementation, not the user code.  In the case of an immutable
      collection, we happily suppress the warning knowing that
      everything is safe.  If we were returning a mutable collection, it
      would be unsafe to suppress the warning, and doing so would be a
      library bug.<br>
      <br>
      We have several ways out of this hole; one is to restrict
      invocation, as you suggest.  Another is to add some unchecked
      warnings.  (Another possible path is to treat signatures of erased
      __SS members, when accessed from outside, as if they contained
      capture variables.)  <br>
      <br>
      <br>
      <br>
    </tt><br>
    <div class="moz-cite-prefix">On 2/17/2016 12:03 PM, Peter Levart
      wrote:<br>
    </div>
    <blockquote cite="mid:56C4A7D5.4010801@gmail.com" type="cite">
      <meta content="text/html; charset=windows-1252"
        http-equiv="Content-Type">
      Hi Brian,<br>
      <br>
      <div class="moz-cite-prefix">On 02/15/2016 07:11 PM, Brian Goetz
        wrote:<br>
      </div>
      <blockquote
        cite="mid:F716FD1E-33D0-4C4A-83BD-3BFE466B17AF@oracle.com"
        type="cite">
        <div><font face="Menlo">Example:<br>
            <br>
            class Collection<any T> {<br>
               private __SS Collection<T> emptyCollection = …<br>
               // ACC_SS field emptyCollection : ParamType[Collection,
            TypeVar[T]]<br>
            <br>
               private __SS Collection<T> emptyCollection() {
            return emptyCollection; }<br>
               ACC_SS emptyCollection()ParamType[Collection, TypeVar[T]]
            {<br>
                   getstatic ParamType[Collection,
            TypeVar[T]].emptyCollection : ParamType[Collection,
            TypeVar[T]]]<br>
                   areturn<br>
               }<br>
            <br>
            When we specialize Collection<int>, the field type,
            method return type, etc, will all collapse to
            Collection<int> by the existing mechanisms.</font></div>
      </blockquote>
      <br>
      This would work if the <font face="Menlo">emptyCollection was
        actually empty and immutable, but could you do the following:<br>
        <br>
        class Collection<any T> {<br>
           private __SS Collection<T>collection = new
        ArrayList<T>();</font><font face="Menlo"><br>
        <br>
           public __SS Collection<T> collection() { return </font><font
        face="Menlo"><font face="Menlo">collection</font>; }</font><font
        face="Menlo"><br>
        }<br>
        <br>
        <br>
        And then in code:<br>
        <br>
        Collection<String> cs =
        Collection<String>.collection();<br>
        Collection<Number> cn =
        Collection<Number>.collection();<br>
        <br>
        cs.add("abc");<br>
        Number n = cn.iterator().next();<br>
      </font><font face="Menlo"><br>
        If cs and cn hold the same instance, we have introduced heap
        corruption without compilation warnings.<br>
        <br>
        So I suppose in language you could only access the _SS members
        in the following way:<br>
        <br>
        Collection<?>.collection();<br>
        Collection<int>.collection();<br>
        Collection<long>.collection();<br>
        Collection<ValueType>.collection();<br>
        ...<br>
        <br>
        but not:<br>
        <br>
        Collection<Object>.collection();<br>
        Collection<String>.collection();<br>
        ...<br>
        <br>
        <br>
        Like .class literals in the prototype.<br>
        <br>
        Regards, Peter<br>
        <br>
        <br>
      </font> </blockquote>
    <br>
  </body>
</html>