Hi Brian,

On 02/15/2016 07:11 PM, Brian Goetz wrote:
Example:

class Collection<any T> {
   private __SS Collection<T> emptyCollection = …
   // ACC_SS field emptyCollection : ParamType[Collection, TypeVar[T]]

private __SS Collection<T> emptyCollection() { return emptyCollection; }
   ACC_SS emptyCollection()ParamType[Collection, TypeVar[T]] {
getstatic ParamType[Collection, TypeVar[T]].emptyCollection : ParamType[Collection, TypeVar[T]]]
       areturn
   }

When we specialize Collection<int>, the field type, method return type, etc, will all collapse to Collection<int> by the existing mechanisms.

This would work if the emptyCollection was actually empty and immutable, but could you do the following:

class Collection<any T> {
   private __SS Collection<T>collection = new ArrayList<T>();

   public __SS Collection<T> collection() { return collection; }
}


And then in code:

Collection<String> cs = Collection<String>.collection();
Collection<Number> cn = Collection<Number>.collection();

cs.add("abc");
Number n = cn.iterator().next();

If cs and cn hold the same instance, we have introduced heap corruption without compilation warnings.

So I suppose in language you could only access the _SS members in the following way:

Collection<?>.collection();
Collection<int>.collection();
Collection<long>.collection();
Collection<ValueType>.collection();
...

but not:

Collection<Object>.collection();
Collection<String>.collection();
...


Like .class literals in the prototype.

Regards, Peter


Reply via email to