Notes on implementing concise calls to constructors with type parameters
Alex Buckley
Alex.Buckley at Sun.COM
Fri May 15 10:05:37 PDT 2009
Ulf Zibis wrote:
>>> It should have stopped them more cold in experiencing a consequently
>>> occurring CCE at runtime. ;-)
>>
>> Which they knew might happen because of the unchecked warning at the
>> assignment, giving them a chance to identify potential heap pollution
>> and upgrade certain uses of raw types at their own pace.
>>
>
> With this same argument, following code should similar output a warning
> instead of a compile time error:
>
> int i;
> ...
> if (i == 7) { // error: variable not initialized
> ...
> }
No, it shouldn't. An unchecked warning indicates a hole is being punched
in the generic type system. Assigning a List to a List<..> is not
statically type correct (List is not a subtype of List<..>) and can lead
to a loss of dynamic type safety. But migration compatibility desires
the assignment to be legal, so an error is impractical. A warning is the
only thing left.
(For the same reason, you ought to get a warning every time you assign
into an array, but there's a level of realism which prevents that.)
Whereas, the assignment type system - where the "type" of i is ASSIGNED
or UNASSIGNED - is much more conservative. No holes may be punched
through it. Either code is statically checkable (==> dynamic type
safety, all variables definitely assigned at runtime), or it's not.
Error, or not.
Alex
More information about the coin-dev
mailing list